Skip to content

Commit 623b942

Browse files
committed
refactor(README): 更新项目描述和特性列表
更改README文件,反映项目名称为“django-project-template”并列出项目模板的特性。 这包括账户界面美化、三方登录、后台管理界面美化、API开发集成和JWT认证。 还提到了附加的项目结构优化和配置,如templates和locale文件夹的创建、appIndex应用的添加,以及调试配置。
1 parent 4b152de commit 623b942

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1941
-2
lines changed

.vscode/launch.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python 调试程序: Django",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"args": [
12+
"runserver",
13+
"0.0.0.0:8080",
14+
],
15+
"django": true,
16+
"autoStartBrowser": false,
17+
"program": "${workspaceFolder}\\manage.py"
18+
}
19+
]
20+
}

MainConfig/__init__.py

Whitespace-only changes.

MainConfig/apis.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ninjia api
2+
from typing import Any
3+
from django.http import HttpRequest
4+
from ninja.security import HttpBearer
5+
from ninja_jwt.controller import NinjaJWTDefaultController
6+
from ninja_jwt.authentication import JWTBaseAuthentication
7+
from ninja_extra import NinjaExtraAPI
8+
9+
10+
11+
#jwt 认证器
12+
from django.contrib.auth import get_user_model
13+
class JWTTokenUser(HttpBearer,JWTBaseAuthentication):
14+
def __init__(self) -> None:
15+
super().__init__()
16+
self.user_model = get_user_model()
17+
def authenticate(self, request: HttpRequest, token: str) -> Any | None:
18+
return super().jwt_authenticate(request, token)
19+
20+
21+
22+
23+
24+
25+
26+
api = NinjaExtraAPI(auth=JWTTokenUser(),csrf=False,version='1.0.0')
27+
api.register_controllers(NinjaJWTDefaultController)
28+
29+
30+
31+
32+
#################################### 测试api ###################################################################
33+
@api.post("/bearer")
34+
def bearer(request):
35+
return {'message': 'hello'}
36+
37+
# @api.get("/add")
38+
# def add(request, a: int, b: int):
39+
# return {"result": a + b}
40+
41+
#####################################################################################################################
42+
# 注册路由,应用api转发
43+
api.add_router("/appindex", "appIndex.apis.router")
44+
45+
46+
47+
48+

MainConfig/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MainConfig.settings")
15+
16+
application = get_asgi_application()

MainConfig/settings.py

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
"""
2+
Django settings for project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
import os
15+
16+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
17+
BASE_DIR = Path(__file__).resolve().parent.parent
18+
19+
20+
# Quick-start development settings - unsuitable for production
21+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
22+
23+
# SECURITY WARNING: keep the secret key used in production secret!
24+
SECRET_KEY = "django-insecure-1tccg@!ew+x-!6vc0p1=u5!%plz^%#yj^i)z1b9r6p4qnzx0er"
25+
26+
# SECURITY WARNING: don't run with debug turned on in production!
27+
DEBUG = True
28+
29+
ALLOWED_HOSTS = []
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = [
35+
'simpleui',
36+
"django.contrib.admin",
37+
"django.contrib.auth",
38+
"django.contrib.contenttypes",
39+
"django.contrib.sessions",
40+
"django.contrib.messages",
41+
"django.contrib.staticfiles",
42+
#bootstrap5
43+
"django_bootstrap5",
44+
# django-allauth
45+
# allauth三方身份认证
46+
'allauth',
47+
'allauth.account',
48+
'allauth.socialaccount',
49+
'allauth.socialaccount.providers.github',
50+
# app
51+
'appIndex',
52+
]
53+
54+
MIDDLEWARE = [
55+
"django.middleware.security.SecurityMiddleware",
56+
"django.contrib.sessions.middleware.SessionMiddleware",
57+
# locale
58+
"django.middleware.locale.LocaleMiddleware",
59+
"django.middleware.common.CommonMiddleware",
60+
"django.middleware.csrf.CsrfViewMiddleware",
61+
"django.contrib.auth.middleware.AuthenticationMiddleware",
62+
"django.contrib.messages.middleware.MessageMiddleware",
63+
# allauth
64+
"allauth.account.middleware.AccountMiddleware",
65+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
66+
67+
]
68+
69+
ROOT_URLCONF = "MainConfig.urls"
70+
71+
TEMPLATES = [
72+
{
73+
"BACKEND": "django.template.backends.django.DjangoTemplates",
74+
"DIRS": [os.path.join(BASE_DIR, 'templates')],
75+
"APP_DIRS": True,
76+
"OPTIONS": {
77+
"context_processors": [
78+
"django.template.context_processors.debug",
79+
"django.template.context_processors.request",
80+
"django.contrib.auth.context_processors.auth",
81+
"django.contrib.messages.context_processors.messages",
82+
83+
# `allauth` needs this from django
84+
'django.template.context_processors.request',
85+
],
86+
87+
},
88+
},
89+
]
90+
91+
WSGI_APPLICATION = "MainConfig.wsgi.application"
92+
93+
94+
# Database
95+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
96+
97+
DATABASES = {
98+
"default": {
99+
"ENGINE": "django.db.backends.sqlite3",
100+
"NAME": BASE_DIR / "db.sqlite3",
101+
}
102+
}
103+
104+
105+
# Password validation
106+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
107+
108+
AUTH_PASSWORD_VALIDATORS = [
109+
{
110+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
111+
},
112+
{
113+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
114+
},
115+
{
116+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
117+
},
118+
{
119+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
120+
},
121+
]
122+
123+
124+
AUTHENTICATION_BACKENDS = [
125+
126+
# Needed to login by username in Django admin, regardless of `allauth`
127+
'django.contrib.auth.backends.ModelBackend',
128+
129+
# `allauth` specific authentication methods, such as login by email
130+
'allauth.account.auth_backends.AuthenticationBackend',
131+
132+
]
133+
134+
# Provider specific settings
135+
SOCIALACCOUNT_PROVIDERS = {
136+
'github': {
137+
'SCOPE': ['user', 'repo']
138+
139+
},
140+
}
141+
142+
#认证登录后跳转
143+
LOGIN_REDIRECT_URL = "/"
144+
145+
# Internationalization
146+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
147+
148+
from django.utils.translation import gettext_lazy as _
149+
LANGUAGE_CODE = "zh-hans" # 默认使用中国时区
150+
151+
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
152+
153+
LANGUAGES = (
154+
("en", _("English")),
155+
("zh-hans", _("Simplified Chinese")),
156+
)
157+
158+
TIME_ZONE = "Asia/Shanghai"
159+
160+
USE_I18N = True
161+
162+
USE_L10N = True
163+
164+
USE_TZ = True
165+
166+
167+
# Static files (CSS, JavaScript, Images)
168+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
169+
170+
STATIC_URL = "static/"
171+
172+
STATICFILES_DIRS = [
173+
os.path.join(BASE_DIR, "static"),
174+
]
175+
176+
# Default primary key field type
177+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
178+
179+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
180+
181+
182+
# email
183+
#邮件配置,需要去三方邮箱开启授权服务
184+
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
185+
EMAIL_HOST = 'smtp.qq.com' # 如果是 163 改成 smtp.163.com
186+
EMAIL_PORT = 465
187+
EMAIL_HOST_USER = '[email protected]' # 发送邮件的邮箱帐号
188+
EMAIL_HOST_PASSWORD = 'ndwuijbugjxnbagc' # 授权码,各邮箱的设置中启用smtp服务时获取
189+
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER #收件人显示发件人的邮箱
190+
# DEFAULT_FROM_EMAIL = '<[email protected]>' #也可以随意写
191+
EMAIL_USE_SSL = True # 使用ssl
192+
# EMAIL_USE_TLS = False # 使用tls
193+
# EMAIL_USE_SSL 和 EMAIL_USE_TLS 是互斥的,即只能有一个为 True
194+
195+

MainConfig/urls.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
URL configuration for project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.1/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
18+
from django.contrib import admin
19+
from django.urls import path
20+
from django.urls import include
21+
from .apis import api
22+
urlpatterns = [
23+
path("admin/", admin.site.urls),
24+
path('accounts/', include('allauth.urls')),
25+
path("i18n/", include("django.conf.urls.i18n")),
26+
path('api/', api.urls),
27+
path("", include(("appIndex.urls","appIndex"), namespace="appIndex"))
28+
]
29+
30+

MainConfig/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MainConfig.settings")
15+
16+
application = get_wsgi_application()

README.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
# FlashCards
2-
一个基于django的创建闪卡集、分享闪卡集、闪卡学习的网站
1+
# django-project-template
2+
3+
一个django项目启动模板。
4+
5+
集成了django-allauth、django-allauth-bootstrap5、simpleui、django-ninja、django-ninja-jwt等django适配的应用,用于提供一个基础设施更加完善的django项目启动模板。
6+
7+
项目模板功能
8+
9+
- [X] 账户相关功能界面美化。基于django-allauth-bootstrap5。
10+
- [X] 三方登录集成。基于django-allauth。
11+
- [X] 后台管理界面美化。基于simpleui。
12+
- [X] api开发集成。基于django-ninja。
13+
- [X] api登录JWT认证。基于django-ninja-jwt.
14+
15+
16+
其他:
17+
18+
* [X] 建立了templates文件夹,用于管理所有前端页面。
19+
* [X] 建立了locale文件夹,用于管理项目语言本地化。
20+
* [X] 建立appIndex应用,作为项目初始主页以及示例。
21+
* [X] 配置vscode调试launch.json文件
22+
* [X] 完成了三方适配应用的相关开箱即用的初始配置。

appIndex/__init__.py

Whitespace-only changes.

appIndex/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

0 commit comments

Comments
 (0)