first commit

This commit is contained in:
2025-11-12 10:57:01 +08:00
commit 79b33e45dc
37 changed files with 416 additions and 0 deletions

0
myapp/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
myapp/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
myapp/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class MyappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'

View File

@@ -0,0 +1,24 @@
# Generated by Django 5.2.8 on 2025-11-12 01:02
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('city', models.CharField(max_length=100)),
('sex', models.CharField(max_length=100)),
('age', models.IntegerField()),
],
),
]

View File

Binary file not shown.

10
myapp/models.py Normal file
View File

@@ -0,0 +1,10 @@
from django.db import models
# Create your models here.
class User(models.Model):
name = models.CharField(max_length=100)
city = models.CharField(max_length=100)
sex = models.CharField(max_length=100)
age = models.IntegerField()

3
myapp/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

9
myapp/urls.py Normal file
View File

@@ -0,0 +1,9 @@
from django.urls import path,include
from myapp import views
urlpatterns = [
path('user/', views.user),
path('user_list/', views.user_list),
path('user_add', views.user_add),
]

34
myapp/views.py Normal file
View File

@@ -0,0 +1,34 @@
from django.shortcuts import render
from django.http import HttpResponse
from myapp.models import User
# Create your views here.
def user(request):
if request.method == 'GET':
return HttpResponse('获取用户')
elif request.method == 'POST':
name = request.POST.get('name')
city = request.POST.get('city')
sex = request.POST.get('sex')
age = request.POST.get('age')
User.objects.create(
name=name,
city=city,
sex = sex,
age = age,
)
print(request.POST)
return HttpResponse('创建用户')
elif request.method == 'PUT':
return HttpResponse('创建用户')
elif request.method == 'DELETE':
return HttpResponse('删除用户')
def user_list(request):
users = User.objects.all()
return render(request, 'user_list.html', {'users': users})
def user_add(request):
return render(request, 'user_add.html')