我在Django中創建了一個簡單的表單,它將輸入作爲用戶名,電子郵件,密碼並將它們添加到數據庫中。現在當我點擊提交按鈕時,URL調度器不會重定向以及更新數據庫。這裏是我的代碼:URL調度器不工作
登錄表單\ urls.py(登錄表單作爲項目):
from django.conf.urls import url, include from django.contrib import admin
app_name = 'authentication'
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^authentication/', include('authentication.urls',namespace="authentication")),
]
認證\ urls.py(身份驗證的應用程序):
from django.conf.urls import url
from .import views
urlpatterns = [
url(r'^$',views.SignIn, name="sign_in"),
url(r'^register/$',views.Register, name="register"),
]
sign_in.html:
{% extends 'authentication/base.html' %}
{% block body %}
<div class="container">
<div class="row">
<div class="col-sm-offset-2 col-sm-8 col-md-offset-3 col-md-6 col-lg-offset-4 col-lg-4">
<fieldset>
<legend> Register </legend>
<from method="post" action="{% url 'authentication:register' %}" >
{% csrf_token %}
<div >
<input name="username" type="username" placeholder="Username" class="form-control">
<input name="email" type="email" placeholder="Email" class="form-control">
<input name="password" type="password" placeholder="Password" class="form-control">
</div>
<br> <button type="submit" class="btn btn-defaul"> Submit </button>
</from>
</fieldset>
</div>
</div>
</div>
{% endblock %}
views.py:
from django.shortcuts import render
from .models import users
def SignIn(request):
return render(request,'authentication/sign_in.html')
def Register(request):
register = users()
register.username = request.POST['username']
register.email = request.POST['email']
register.password = request.POST['password']
register.save()
return render(request,'authentication/profile.html',{'username': register.username })
感謝你的好意:)
您是否曾嘗試向「SignIn」和「Register」視圖添加日誌記錄以確保它們被調用? – 2016-12-29 08:51:15
在您的模板中,'
成功註冊後,您嘗試在哪個URL上重定向。 –