# 子应用users的视图路由 from django.urls import path from users.views import RegisterView, ImageCodeView, SmsView urlpatterns = [ # path参数一: 路由 # path参数二: 视图函数名 # 注册用户页 path('register/', RegisterView.as_view(), name='register'), # 图片验证码 path('imagecode/', ImageCodeView.as_view(), name='imagecode'), # sms path('smscode/', SmsView.as_view(), name='smscode'), ]
Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url, include from django.views.static import serve from rest_framework.routers import DefaultRouter from SMSReg.settings import MEDIA_ROOT from users.views import UserViewset, SmsCodeViewset, ImageCodeView router = DefaultRouter() # 用户接口 router.register(r'users', UserViewset, base_name="users") # 短信验证码接口 router.register(r'codes', SmsCodeViewset, base_name="codes") urlpatterns = [ url(r'^', include(router.urls)), # 图片验证码 url(r'^imagecode', ImageCodeView.as_view(), name='imagename'), # 访问图片URL url(r'^media/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT}), ]
# 进行users 子应用的视图路由 from django.urls import path from users.views import RegisterView, ImageCodeView, SmsCodeView, LoginView, LogoutView, ForgetPasswordView, UserCenterView, WriteBlogView, SelfBlogView urlpatterns = [ # path第一个参数:路由 # path第二个参数:视图函数名 path('register/', RegisterView.as_view(), name='register'), # 图片验证码路由 path('imagecode/', ImageCodeView.as_view(), name='imagecode'), # 短信发送路由 path('smscode/', SmsCodeView.as_view(), name='smscode'), # 登录路由 path('login/', LoginView.as_view(), name='login'), # 登出路由 path('logout/', LogoutView.as_view(), name='logout'), # 忘记密码路由 path('forget_password/', ForgetPasswordView.as_view(), name='forgetpassword'), # 用户中心路由 path('center/', UserCenterView.as_view(), name='center'), # 写博客路由 path('write_blog/', WriteBlogView.as_view(), name='writeblog'), # 个人博客路由 path('self_blog/', SelfBlogView.as_view(), name='selfblog') ]
from django.urls import path from users.views import RegisterBht from users.views import LoginBht from users.views import ImageCodeView from users.views import SmsCodeView from users.views import LogoutView from users.views import ForgetPasswordView from users.views import UserCenterView from users.views import WriteBlogView urlpatterns = [ # 参数1:路由 # 参数2:视图函数 # 参数3:方便通过reverse来获取路由 path("register/", RegisterBht.as_view(), name='register'), # 登陆路由 path('login/', LoginBht.as_view(), name='login'), # 退出登录 path('logout/', LogoutView.as_view(), name='logout'), # 忘记密码 path('forgetpassword/', ForgetPasswordView.as_view(), name='forgetpassword'), # 图片验证码路由 path('imagecode/', ImageCodeView.as_view()), # 短信发送 path('smscode/', SmsCodeView.as_view()), # 用户中心 path('center/', UserCenterView.as_view(), name='center'), #写博客 path('writeblog/', WriteBlogView.as_view(), name='writeblog'), ]
from django.urls import path from users.views import RegisterView, ImageCodeView, SmsCodeView, LoginView from users.views import LogoutView, ForgetPasswordView, UserCenterView, WriteBlogView urlpatterns = [ # 参数1:路由 # 参数2:视图函数 # 参数3:路由名,方便通过reverse来获取路由 path("register/", RegisterView.as_view(), name="register"), path("imagecode/", ImageCodeView.as_view(), name="imagecode"), path("smscode/", SmsCodeView.as_view(), name="smscode"), path("login/", LoginView.as_view(), name="login"), path("logout/", LogoutView.as_view(), name="logout"), path("forgetpassword/", ForgetPasswordView.as_view(), name="forgetpassword"), path("center/", UserCenterView.as_view(), name="center"), path("writeblog/", WriteBlogView.as_view(), name="writeblog"), ]