标签:ddl gem url pattern -- middle get color got
urls:
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘login/‘, views.Login.as_view())#类方法url对应方式,Login为类名
path(‘login/‘, views.Login)#函数方法url对应方式,Login为函数名
]
setting:
STATIC_URL = ‘/static/‘
STATICFILES_DIRS = (
os.path.join(BASE_DIR, ‘static‘),
)
MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware‘,
‘django.contrib.sessions.middleware.SessionMiddleware‘,
‘django.middleware.common.CommonMiddleware‘,
# ‘django.middleware.csrf.CsrfViewMiddleware‘, #注销这一行
‘django.contrib.auth.middleware.AuthenticationMiddleware‘,
‘django.contrib.messages.middleware.MessageMiddleware‘,
‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,
]
TEMPLATES = [
{
‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
‘DIRS‘: [os.path.join(BASE_DIR, ‘html‘)], #添加路径
‘APP_DIRS‘: True,
app01下的views:
class Login(View):
def get(self, request):
print(request.method)
return render(request, ‘login.html‘)
def post(self, request):
print(request.method)
return render(request, ‘login.html‘)
html下的action=“/login”对应的是 ---> urls.py里的 path(‘login/‘, views.Login.as_view()) ---> views里的class Login
标签:ddl gem url pattern -- middle get color got
原文地址:https://www.cnblogs.com/fengzi7314/p/9334930.html