diff --git a/Django5/settings.py b/Django5/settings.py index 9a68515..89733c9 100644 --- a/Django5/settings.py +++ b/Django5/settings.py @@ -35,7 +35,9 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - "helloWorld.apps.HelloworldConfig" + "helloWorld.apps.HelloworldConfig", + "user.apps.UserConfig", + "order.apps.OrderConfig" ] MIDDLEWARE = [ diff --git a/Django5/urls.py b/Django5/urls.py index 8076b69..f2cf339 100644 --- a/Django5/urls.py +++ b/Django5/urls.py @@ -16,7 +16,7 @@ Including another URLconf """ from django.conf import settings from django.contrib import admin -from django.urls import path, re_path +from django.urls import path, re_path, include from django.views.generic import RedirectView from django.views.static import serve @@ -46,8 +46,11 @@ urlpatterns = [ # 媒体路由 re_path('media/(?P.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'), - # 路由重定向,用RedirectVIew实现 # 访问http://localhost:8000/redirectTo直接跳转到http://localhost:8000/index/ - path('redirectTo',RedirectView.as_view(url="index/")), + path('redirectTo', RedirectView.as_view(url="index/")), + + # 给路由分路由出来并命名 + path('user/', include(('user.urls','user'), namespace='user')), + path('order/', include(('order.urls','order'), namespace='order')), ] diff --git a/order/__init__.py b/order/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/order/admin.py b/order/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/order/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/order/apps.py b/order/apps.py new file mode 100644 index 0000000..42888e4 --- /dev/null +++ b/order/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class OrderConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'order' diff --git a/order/migrations/__init__.py b/order/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/order/models.py b/order/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/order/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/order/tests.py b/order/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/order/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/order/urls.py b/order/urls.py new file mode 100644 index 0000000..cb9580a --- /dev/null +++ b/order/urls.py @@ -0,0 +1,25 @@ +""" +URL configuration for Django5 project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +import order.views + +urlpatterns = [ + path('admin/', admin.site.urls), + path('index/', order.views.index), +] diff --git a/order/views.py b/order/views.py new file mode 100644 index 0000000..a4610a5 --- /dev/null +++ b/order/views.py @@ -0,0 +1,5 @@ +from django.http import HttpResponse +# Create your views here. + +def index(request): + return HttpResponse("订单信息") \ No newline at end of file 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/__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..71a8362 --- /dev/null +++ b/user/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. 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..0ca32d3 --- /dev/null +++ b/user/urls.py @@ -0,0 +1,26 @@ +""" +URL configuration for Django5 project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +import user.views + +urlpatterns = [ + path('admin/', admin.site.urls), + path('index/', user.views.index), + path('list/', user.views.list), +] diff --git a/user/views.py b/user/views.py new file mode 100644 index 0000000..e83dad3 --- /dev/null +++ b/user/views.py @@ -0,0 +1,8 @@ +from django.http import HttpResponse +# Create your views here. + +def index(request): + return HttpResponse("用户信息") + +def list(request): + return HttpResponse("用户列表") \ No newline at end of file