🌈 🌤

零、项目搭建

0.1 路由分发

  • 全局路由urls.py

    from django.urls import path, include
    urlpatterns = [
      	# 1、路由分发
        path('', include('app01.urls')),
        path('app01/', include('app01.urls')),
        path('app02/', include('app02.urls')),
    ]
    
  • 局部路由app01/urls.py

    from django.urls import path
    from app01 import views
    urlpatterns = [
      	# 2、路由分发
        path('login/', views.login),
        path('reg/', views.reg),
    ]
    

0.2 视图函数

  • app01/views.py

    from django.shortcuts import render, redirect, HttpResponse
    # 3、视图函数
    def login(request):
    		pass
      	# 4、模版
    		return render(request, "login.html", locals())
    def reg(request):
    		pass
    		return render(request, "reg.html", locals())
    

0.3 模版templates

  • templates/login.html
  • templates/reg.html

0.4 静态文件static

  • settings.py

    STATIC_URL = '/static/'
    # 静态文件路径
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static')
    ]
    
posted @ 2021-02-20 20:39  xiangjianan  阅读(68)  评论(0)    收藏  举报