diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b6b1ecf..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# 默认忽略的文件 -/shelf/ -/workspace.xml -# 已忽略包含查询文件的默认文件夹 -/queries/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# 基于编辑器的 HTTP 客户端请求 -/httpRequests/ diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index a41bbad..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -chunyu_project \ No newline at end of file diff --git a/.idea/chunyu_project.iml b/.idea/chunyu_project.iml index b0e75c3..a61e205 100644 --- a/.idea/chunyu_project.iml +++ b/.idea/chunyu_project.iml @@ -3,9 +3,9 @@ - diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml new file mode 100644 index 0000000..80a5cf0 --- /dev/null +++ b/.idea/dataSources.local.xml @@ -0,0 +1,18 @@ + + + + + + " + + + master_key + no-auth + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..6f9b70e --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:C:\Users\12914\PycharmProjects\chunyu_project\db.sqlite3 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/dataSources/5d549d8f-5ef2-47b0-97e6-f6c77b1b0b38.xml b/.idea/dataSources/5d549d8f-5ef2-47b0-97e6-f6c77b1b0b38.xml new file mode 100644 index 0000000..7fa2987 --- /dev/null +++ b/.idea/dataSources/5d549d8f-5ef2-47b0-97e6-f6c77b1b0b38.xml @@ -0,0 +1,2263 @@ + + + + + 3.51.1 + + + + + + + + + + + + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + + window + + + 1 + + + 1 + + + 1 + + + + 1 + 1 + + + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + + + window + + + window + + + window + + + + + + 1 + 1 + + + 1 + 1 + + + 1 + + + window + + + + 1 + + + window + + + 1 + + + 1 + 1 + + + + + + 1 + + + + + 1 + + + 1 + + + window + + + window + + + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + window + + + 1 + window + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + window + + + 1 + window + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + window + + + window + + + window + + + + window + + + window + + + window + + + window + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + aggregate + + + 1 + + + 1 + + + + + + 1 + 1 + + + window + + + aggregate + + + 1 + 1 + + + window + + + 1 + + + aggregate + + + window + + + window + + + 1 + + + 1 + + + + + + + + window + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + + 1 + + + 1 + + + + + window + + + 1 + + + 1 + + + + + + 1 + + + 1 + + + window + + + 1 + + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + 1 + + + + aggregate + + + + 1 + 1 + + + window + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + window + + + 1 + + + 1 + + + 1 + 1 + + + 1 + + + window + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + + + aggregate + + + aggregate + + + 1 + + + 1 + 2026-03-25.21:28:57 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + 3 + + + R + + + R + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + R + + + R + + + R + + + R + + + R + + + R + + + 1 + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + R + + + 1 + + + 2 + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + R + + + 1 + + + 2 + + + R + + + R + + + R + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + 3 + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + 3 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + 3 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + R + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + R + + + R + + + 1 + + + 2 + + + 3 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + 3 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + 2 + + + 3 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + 2 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + + R + + + 1 + + +
+
+
+
+
+
+
+
+
+
+ 1 +
+ + 1 +
+ + 1 + 1 + 1 + integer|0s + + + 1 + 2 + varchar(150)|0s + + + name + 1 + 1 + + + id + 1 + + + name + sqlite_autoindex_auth_group_1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + integer|0s + + + 1 + 3 + integer|0s + + + group_id + 1 + 1 + id + auth_group + + + permission_id + 1 + 1 + id + auth_permission + + + group_id +permission_id + 1 + + + group_id + + + permission_id + + + id + 1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + integer|0s + + + 1 + 3 + varchar(100)|0s + + + 1 + 4 + varchar(255)|0s + + + content_type_id + 1 + 1 + id + django_content_type + + + content_type_id +codename + 1 + + + content_type_id + + + id + 1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + varchar(128)|0s + + + 3 + datetime|0s + + + 1 + 4 + bool|0s + + + 1 + 5 + varchar(150)|0s + + + 1 + 6 + varchar(150)|0s + + + 1 + 7 + varchar(254)|0s + + + 1 + 8 + bool|0s + + + 1 + 9 + bool|0s + + + 1 + 10 + datetime|0s + + + 1 + 11 + varchar(150)|0s + + + username + 1 + 1 + + + id + 1 + + + username + sqlite_autoindex_auth_user_1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + integer|0s + + + 1 + 3 + integer|0s + + + user_id + 1 + 1 + id + auth_user + + + group_id + 1 + 1 + id + auth_group + + + user_id +group_id + 1 + + + user_id + + + group_id + + + id + 1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + integer|0s + + + 1 + 3 + integer|0s + + + user_id + 1 + 1 + id + auth_user + + + permission_id + 1 + 1 + id + auth_permission + + + user_id +permission_id + 1 + + + user_id + + + permission_id + + + id + 1 + + + "action_flag" >= 0 + + + 1 + 1 + 1 + integer|0s + + + 2 + text|0s + + + 1 + 3 + varchar(200)|0s + + + 1 + 4 + smallint unsigned|0s + + + 1 + 5 + text|0s + + + 6 + integer|0s + + + 1 + 7 + integer|0s + + + 1 + 8 + datetime|0s + + + content_type_id + 1 + 1 + id + django_content_type + + + user_id + 1 + 1 + id + auth_user + + + content_type_id + + + user_id + + + id + 1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + varchar(100)|0s + + + 1 + 3 + varchar(100)|0s + + + app_label +model + 1 + + + id + 1 + + + 1 + 1 + 1 + integer|0s + + + 1 + 2 + varchar(255)|0s + + + 1 + 3 + varchar(255)|0s + + + 1 + 4 + datetime|0s + + + id + 1 + + + 1 + 1 + varchar(40)|0s + + + 1 + 2 + text|0s + + + 1 + 3 + datetime|0s + + + session_key + 1 + 1 + + + expire_date + + + session_key + 1 + sqlite_autoindex_django_session_1 + + + 1 + TEXT|0s + + + 2 + TEXT|0s + + + 3 + TEXT|0s + + + 4 + INT|0s + + + 5 + TEXT|0s + + + 1 + + + 2 + +
+
\ No newline at end of file diff --git a/.idea/dataSources/5d549d8f-5ef2-47b0-97e6-f6c77b1b0b38/storage_v2/_src_/schema/main.uQUzAA.meta b/.idea/dataSources/5d549d8f-5ef2-47b0-97e6-f6c77b1b0b38/storage_v2/_src_/schema/main.uQUzAA.meta new file mode 100644 index 0000000..8dab49c --- /dev/null +++ b/.idea/dataSources/5d549d8f-5ef2-47b0-97e6-f6c77b1b0b38/storage_v2/_src_/schema/main.uQUzAA.meta @@ -0,0 +1,2 @@ +#n:main +! [0, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index b98efe7..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index fe41fa9..972686f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..43b9cd2 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 7 +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + C:\Users\12914\AppData\Roaming\Subversion + + + + + 1774436691939 + + + + + + + + + \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..8ccd35b --- /dev/null +++ b/Pipfile @@ -0,0 +1,14 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +django = "==4.2.29" +djangorestframework = "==3.17.1" + +[dev-packages] + +[requires] +python_version = "3.12" +python_full_version = "3.12.10" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..21bec85 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,64 @@ +{ + "_meta": { + "hash": { + "sha256": "2261b9cfef97e6fd2579aae2dd07367326124e96a21f016cc0bd771db5d7213d" + }, + "pipfile-spec": 6, + "requires": { + "python_full_version": "3.12.10", + "python_version": "3.12" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "asgiref": { + "hashes": [ + "sha256:5f184dc43b7e763efe848065441eac62229c9f7b0475f41f80e207a114eda4ce", + "sha256:e8667a091e69529631969fd45dc268fa79b99c92c5fcdda727757e52146ec133" + ], + "markers": "python_version >= '3.9'", + "version": "==3.11.1" + }, + "django": { + "hashes": [ + "sha256:074d7c4d2808050e528388bda442bd491f06def4df4fe863f27066851bba010c", + "sha256:86d91bc8086569c8d08f9c55888b583a921ac1f95ed3bdc7d5659d4709542014" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==4.2.29" + }, + "djangorestframework": { + "hashes": [ + "sha256:a6def5f447fe78ff853bff1d47a3c59bf38f5434b031780b351b0c73a62db1a5", + "sha256:c3c74dd3e83a5a3efc37b3c18d92bd6f86a6791c7b7d4dff62bb068500e76457" + ], + "index": "pypi", + "markers": "python_version >= '3.10'", + "version": "==3.17.1" + }, + "sqlparse": { + "hashes": [ + "sha256:12a08b3bf3eec877c519589833aed092e2444e68240a3577e8e26148acc7b1ba", + "sha256:e20d4a9b0b8585fdf63b10d30066c7c94c5d7a7ec47c889a2d83a3caa93ff28e" + ], + "markers": "python_version >= '3.8'", + "version": "==0.5.5" + }, + "tzdata": { + "hashes": [ + "sha256:06a47e5700f3081aab02b2e513160914ff0694bce9947d6b76ebd6bf57cfc5d1", + "sha256:de39c2ca5dc7b0344f2eba86f49d614019d29f060fc4ebc8a417896a620b56a7" + ], + "markers": "python_version >= '2'", + "version": "==2025.3" + } + }, + "develop": {} +} diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..cd1f572 --- /dev/null +++ b/api/urls.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from django.urls import path, include +from .views.GetIPDataView import GetIPData + +urlpatterns = [ + path("getIpData/", GetIPData.as_view()), +] \ No newline at end of file diff --git a/api/views/__init__.py b/api/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/apps.py b/app/apps.py index 80b2c8d..ed327d2 100644 --- a/app/apps.py +++ b/app/apps.py @@ -2,4 +2,5 @@ from django.apps import AppConfig class AppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' name = 'app' diff --git a/app/models.py b/app/models.py index 71a8362..e69de29 100644 --- a/app/models.py +++ b/app/models.py @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/app/tests.py b/app/tests.py index 7ce503c..e69de29 100644 --- a/app/tests.py +++ b/app/tests.py @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/app/urls.py b/app/urls.py new file mode 100644 index 0000000..1a4e336 --- /dev/null +++ b/app/urls.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from django.urls import path, include +urlpatterns = [ + + +] \ No newline at end of file diff --git a/chunyu_project/asgi.py b/chunyu_project/asgi.py index 1628b35..fc92230 100644 --- a/chunyu_project/asgi.py +++ b/chunyu_project/asgi.py @@ -1,16 +1,7 @@ -""" -ASGI config for chunyu_project project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/ -""" - import os - from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chunyu_project.settings') -application = get_asgi_application() +# Django 默认 ASGI 应用 +application = get_asgi_application() \ No newline at end of file diff --git a/chunyu_project/settings.py b/chunyu_project/settings.py index d36fe79..f9df25e 100644 --- a/chunyu_project/settings.py +++ b/chunyu_project/settings.py @@ -11,38 +11,165 @@ https://docs.djangoproject.com/en/6.0/ref/settings/ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ +# 安全设置 +SECURE_SSL_REDIRECT = False +SESSION_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = False +SECURE_HSTS_SECONDS = 31536000 +SECURE_HSTS_INCLUDE_SUBDOMAINS = True +SECURE_HSTS_PRELOAD = True +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') + # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-j+-psq=m++l7hup73k1eg+wm-b&2_)!+_^o=6(=xc$1px*kqt@' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +# 生产环境配置 +if not DEBUG: + # 从环境变量获取,并过滤空值 + cors_env = os.environ.get('CORS_ALLOWED_ORIGINS', '') + if cors_env: + # 解析并验证每个 origin + allowed_origins = [] + for origin in cors_env.split(','): + origin = origin.strip() + if origin: # 非空 + # 确保有协议(http:// 或 https://) + if not origin.startswith(('http://', 'https://')): + # 自动添加 https:// + origin = f'https://{origin}' + allowed_origins.append(origin) -# Application definition + CORS_ALLOWED_ORIGINS = allowed_origins + CORS_ALLOW_ALL_ORIGINS = False + else: + # 如果没有设置,使用默认 + CORS_ALLOWED_ORIGINS = [] + CORS_ALLOW_ALL_ORIGINS = False +else: + # 开发环境 + CORS_ALLOW_ALL_ORIGINS = True + CORS_ALLOWED_ORIGINS = [] + +ALLOWED_HOSTS = ["*"] + +CORS_ALLOWED_ORIGINS = [ + "http://localhost:3000", # 例如:您的React/Vue开发服务器 + "http://127.0.0.1:3000", +] + +# CORS设置 +CORS_ALLOW_ALL_ORIGINS = False + +# 允许凭据 +CORS_ALLOW_CREDENTIALS = True + +# 允许的请求头 +CORS_ALLOW_HEADERS = [ + 'accept', + 'accept-encoding', + 'authorization', + 'content-type', + 'dnt', + 'origin', + 'user-agent', + 'x-csrftoken', + 'x-requested-with', +] + +# 允许的 HTTP 方法 +CORS_ALLOW_METHODS = [ + 'DELETE', + 'GET', + 'OPTIONS', + 'PATCH', + 'POST', + 'PUT', +] + +CORS_PREFLIGHT_MAX_AGE = 86400 + +REST_FRAMEWORK = { + 'DEFAULT_RENDERER_CLASSES': [ + 'rest_framework.renderers.JSONRenderer', + ], + 'DEFAULT_PARSER_CLASSES': [ + 'rest_framework.parsers.JSONParser', + ], + + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework_simplejwt.authentication.JWTAuthentication', + 'rest_framework.authentication.SessionAuthentication', + # 如果您不需要标准的TokenAuthentication,可以移除下面这行 + # 'rest_framework.authentication.TokenAuthentication', + ], + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.IsAuthenticated', + ], +} + +from datetime import timedelta + +# Simple JWT 设置 +SIMPLE_JWT = { + 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60), # 访问令牌有效期 + 'REFRESH_TOKEN_LIFETIME': timedelta(days=7), # 刷新令牌有效期 + 'ROTATE_REFRESH_TOKENS': True, # 刷新访问令牌时返回新刷新令牌 + 'BLACKLIST_AFTER_ROTATION': True, # 启用黑名单应用(需安装django-rest-framework-simplejwt.token_blacklist) + 'UPDATE_LAST_LOGIN': True, # 更新用户最后登录时间 + + 'ALGORITHM': 'HS256', # 加密算法 + 'SIGNING_KEY': SECRET_KEY, # 签名密钥,使用您的SECRET_KEY + 'VERIFYING_KEY': None, + 'AUDIENCE': None, + 'ISSUER': None, + + 'AUTH_HEADER_TYPES': ('Bearer',), # 认证头前缀,通常是`Bearer` + 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION', + 'USER_ID_FIELD': 'id', # 用户模型标识字段 + 'USER_ID_CLAIM': 'user_id', +} + +AUTH_USER_MODEL = 'user.FUser' INSTALLED_APPS = [ + 'app.apps.AppConfig', + "user.apps.UserConfig", + "api.apps.ApiConfig", + 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - 'django.contrib.staticfiles', - 'app.apps.AppConfig', + + + # 第三方应用 + 'rest_framework', + 'rest_framework_simplejwt', + 'corsheaders', + 'channels', + 'django_filters', + 'drf_yasg', + 'django_extensions', + ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -68,7 +195,7 @@ TEMPLATES = [ }, ] -WSGI_APPLICATION = 'chunyu_project.wsgi.application' +ASGI_APPLICATION = 'chunyu_project.asgi.application' # Database diff --git a/chunyu_project/urls.py b/chunyu_project/urls.py index 9344222..4aea998 100644 --- a/chunyu_project/urls.py +++ b/chunyu_project/urls.py @@ -15,8 +15,14 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include + + urlpatterns = [ path('admin/', admin.site.urls), + path('user/', include('user.urls')), + path("api/", include('api.urls')), + path("app/", include('app.urls')), ] + diff --git a/chunyu_project/wsgi.py b/chunyu_project/wsgi.py deleted file mode 100644 index c37b8fd..0000000 --- a/chunyu_project/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for chunyu_project project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chunyu_project.settings') - -application = get_wsgi_application() diff --git a/db.sqlite3 b/db.sqlite3 index e69de29..06eda8e 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/identifier.sqlite b/identifier.sqlite new file mode 100644 index 0000000..e69de29 diff --git a/user/__init__.py b/user/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user/admin.py b/user/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/user/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/user/apps.py b/user/apps.py new file mode 100644 index 0000000..36cce4c --- /dev/null +++ b/user/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'user' diff --git a/user/migrations/0001_initial.py b/user/migrations/0001_initial.py new file mode 100644 index 0000000..525cdf0 --- /dev/null +++ b/user/migrations/0001_initial.py @@ -0,0 +1,47 @@ +# Generated by Django 5.2.12 on 2026-03-25 21:58 + +import django.contrib.auth.models +import django.contrib.auth.validators +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='FUser', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), + ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), + ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('phone_number', models.CharField(blank=True, max_length=15, verbose_name='手机号')), + ('avatar', models.ImageField(blank=True, null=True, upload_to='avatars/', verbose_name='头像')), + ('bio', models.TextField(blank=True, max_length=500, verbose_name='个人简介')), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/user/migrations/__init__.py b/user/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user/models.py b/user/models.py new file mode 100644 index 0000000..5d1c288 --- /dev/null +++ b/user/models.py @@ -0,0 +1,18 @@ +from django.contrib.auth.models import AbstractUser +from django.db import models + + +class FUser(AbstractUser): + + + phone_number = models.CharField(max_length=15, blank=True, verbose_name='手机号') + avatar = models.ImageField(upload_to='avatars/', blank=True, null=True, verbose_name='头像') + bio = models.TextField(max_length=500, blank=True, verbose_name='个人简介') + + # class Meta: + # # 定义在管理后台显示的名称 + # verbose_name = '用户' + # verbose_name_plural = verbose_name + + def __str__(self): + return self.username \ No newline at end of file diff --git a/user/tests.py b/user/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/user/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/user/urls.py b/user/urls.py new file mode 100644 index 0000000..3a944c4 --- /dev/null +++ b/user/urls.py @@ -0,0 +1,16 @@ +from django.contrib import admin +from django.urls import path, include +from rest_framework_simplejwt.views import ( + TokenObtainPairView, + TokenRefreshView, + TokenVerifyView, +) + +urlpatterns = [ + # JWT 认证接口 + path('user/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), + path('user/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), + path('user/token/verify/', TokenVerifyView.as_view(), name='token_verify'), + + +] \ No newline at end of file diff --git a/user/views.py b/user/views.py new file mode 100644 index 0000000..956f8b0 --- /dev/null +++ b/user/views.py @@ -0,0 +1,15 @@ +from django.urls import path, include +from rest_framework_simplejwt.views import ( + TokenObtainPairView, + TokenRefreshView, + TokenVerifyView, +) + +urlpatterns = [ + # JWT 认证接口 + path('user/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), + path('user/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), + path('user/token/verify/', TokenVerifyView.as_view(), name='token_verify'), + + +] \ No newline at end of file