我是新手Django dev,我对urls配置有点问题。我想制作网址http://localhost:8000/user-auth/register/ 在我的项目中,有一个user_auth应用程序,其中包含以下网址:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^register$', views.register),
]
在我网站的网址中注册此网址:
from django.conf.urls import include, url
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^polls/', include('polls.urls')),
url(r'^user-auth/', include('user_auth.urls')),
]
在我看来,user_auth / views.py:
from django.shortcuts import render
from django.http import HttpResponse
from .forms import RegisterForm
def register(request):
if request.method == 'POST':
response = HttpResponse()
response.write("<h1>Thanks for registering</h1></br>")
response.write("Your username:" + request.POST['username'])
response.write("Your email" + request.POST['email'])
return response
registerForm = RegisterForm()
return render(request, 'user_auth/register.html', {'form':registerForm})
在我的user_auth / forms.py
中from django import forms
class RegisterForm(forms.Form):
username = forms.CharField(label='Username', max_length=100)
password = forms.CharField(widget=forms.PasswordInput)
email = forms.EmailField(label='Email')
当我访问链接http://localhost:8000/user-auth/register/时,控制台宣布&#34;未找到:/ user-auth / register /&#34;。我不知道原因和原因。你能帮我解决这个问题吗? TKS