Skip to content

Commit 2d50047

Browse files
committed
重新复习创建项目
1 parent ad472c8 commit 2d50047

33 files changed

+263
-6
lines changed

.idea/django_learning.iml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+150
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/__init__.py

Whitespace-only changes.

book/admin.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
from book.models import *
3+
4+
# Register your models here.
5+
admin.site.register(Book)
6+
admin.site.register(Person)

book/apps.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BookConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'book'
7+
verbose_name = "书目管理"

book/migrations/0001_initial.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 4.0.3 on 2022-04-08 07:47
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Book',
17+
fields=[
18+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('name', models.CharField(max_length=10)),
20+
],
21+
),
22+
migrations.CreateModel(
23+
name='Person',
24+
fields=[
25+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26+
('name', models.CharField(max_length=10)),
27+
('gender', models.BooleanField()),
28+
('detail', models.CharField(max_length=100)),
29+
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='book.book')),
30+
],
31+
),
32+
]

book/migrations/__init__.py

Whitespace-only changes.

book/models.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.db import models
2+
3+
4+
# Create your models here.
5+
class Book(models.Model):
6+
name = models.CharField(max_length=10)
7+
8+
def __str__(self):
9+
return self.name
10+
11+
12+
class Person(models.Model):
13+
name = models.CharField(max_length=10)
14+
gender = models.BooleanField()
15+
detail = models.CharField(max_length=100)
16+
book = models.ForeignKey(Book, on_delete=models.CASCADE)
17+
18+
def __str__(self):
19+
return self.name

book/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

book/urls.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.urls import path
2+
from book.views import index
3+
urlpatterns = [
4+
path('index/', index)
5+
]

book/views.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.shortcuts import render
2+
3+
context = {
4+
"person": {
5+
"name": "诸葛亮",
6+
"detail": "军师",
7+
}
8+
}
9+
10+
11+
# Create your views here.
12+
def index(request):
13+
return render(request, 'book/index.html', context)

db.sqlite3

140 KB
Binary file not shown.

django_learning/settings.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

28-
ALLOWED_HOSTS = []
28+
ALLOWED_HOSTS = ['*']
2929

3030

3131
# Application definition
@@ -37,6 +37,7 @@
3737
'django.contrib.sessions',
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
40+
'book.apps.BookConfig',
4041
]
4142

4243
MIDDLEWARE = [
@@ -54,7 +55,7 @@
5455
TEMPLATES = [
5556
{
5657
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57-
'DIRS': [],
58+
'DIRS': [BASE_DIR / 'templates'],
5859
'APP_DIRS': True,
5960
'OPTIONS': {
6061
'context_processors': [
@@ -103,9 +104,9 @@
103104
# Internationalization
104105
# https://docs.djangoproject.com/en/4.0/topics/i18n/
105106

106-
LANGUAGE_CODE = 'en-us'
107+
LANGUAGE_CODE = 'zh-hans'
107108

108-
TIME_ZONE = 'UTC'
109+
TIME_ZONE = 'Asia/Shanghai'
109110

110111
USE_I18N = True
111112

@@ -116,7 +117,9 @@
116117
# https://docs.djangoproject.com/en/4.0/howto/static-files/
117118

118119
STATIC_URL = 'static/'
119-
120+
STATICFILES_DIRS = [
121+
BASE_DIR / 'static',
122+
]
120123
# Default primary key field type
121124
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
122125

django_learning/urls.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.contrib import admin
17-
from django.urls import path
17+
from django.urls import path, include
1818

1919
urlpatterns = [
2020
path('admin/', admin.site.urls),
21+
path('book/', include('book.urls'))
2122
]

static/ev0016.png

1.19 MB
Loading

static/ev0021.png

1.19 MB
Loading

static/ev12a.bmp

5.93 MB
Binary file not shown.

static/ev12b.bmp

5.93 MB
Binary file not shown.

static/ev13a.bmp

9.49 MB
Binary file not shown.

static/ev13b.bmp

9.49 MB
Binary file not shown.

static/ev14.bmp

5.93 MB
Binary file not shown.

static/ev15.bmp

5.93 MB
Binary file not shown.

static/ev16.bmp

5.93 MB
Binary file not shown.

static/ev17a.bmp

7.73 MB
Binary file not shown.

static/ev17b.bmp

7.73 MB
Binary file not shown.

static/ev18.bmp

5.93 MB
Binary file not shown.

static/ev19.bmp

5.93 MB
Binary file not shown.

static/ev20.bmp

5.93 MB
Binary file not shown.

static/ev21.bmp

5.93 MB
Binary file not shown.

static/ev22.bmp

5.93 MB
Binary file not shown.

static/ev23.bmp

5.93 MB
Binary file not shown.

static/ev24a.bmp

19.6 MB
Binary file not shown.

templates/book/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>首页</title>
6+
</head>
7+
<body>
8+
<ul>
9+
<li>{{ person.name }}</li>
10+
<li>{{ person.detail }}</li>
11+
</ul>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)