我收到了一个错误。 我认为urls.py或模板是错误的,但我不知道如何解决它。 此外,我认为urls.py&模板没有任何不好的地方。我怎么修理它们? 我在urls.py中写道,
from django.conf.urls import url
from . import views
from django.contrib.auth.views import login, logout
urlpatterns = [
url(r'^login/$', login,
{'template_name': 'registration/accounts/login.html'},
name='login'),
url(r'^logout/$', logout, name='logout'),
url(r'^regist/$', views.regist,name='regist' ),
url(r'^regist_save/$', views.regist_save, name='regist_save'),
]
在views.py中
@login_required
def profile(request):
context = {
'user': request.user,
}
return render(request, 'registration/accounts/profile.html', context)
def regist(request):
form = RegisterForm(request.POST or None)
context = {
'form': form,
}
return render(request, 'registration/accounts/regist.html', context)
@require_POST
def regist_save(request):
form = RegisterForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
return redirect('registration/accounts/profile.html', context)
context = {
'form': form,
}
return render(request, 'accounts/regist.html', context)
在profile.html(模板)
中{% extends "registration/accounts/base.html" %}
{% block content %}
user.username : {{ user.username }}<hr>
user.is_staff: {{ user.is_staff }}<hr>
user.is_active: {{ user.is_active }}<hr>
user.last_login : {{ user.last_login }}<hr>
user.date_joined: {{ user.date_joined }}
{% endblock %}