Answer the question
In order to leave comments, you need to log in
Problems writing a logging form?
I am writing an educational website. I wrote a logging page, everything is displayed correctly, but as soon as I click ok, it goes to the wrong link, generally goes to a link I don't understand.
Here is my views.py:
def index(request):
if request.user.is_authenticated():
return render(request, 'account/index.html',
{
'user' : request.user,
}
)
else:
return HttpResponseRedirect(reverse('account.views.login'))
def logout(request):
if request.user.is_authenticated():
auth.logout(request)
return HttpResponseRedirect(reverse('account.views.login'))
def login(request):
if request.method == 'POST':
f = LoginForm(request.POST)
if f.is_valid():
username = f.cleaned_data['username']
password = f.cleaned_data['password']
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect(reverse('account.views.index'))
else:
f = LoginForm()
return render(request, 'account/login.html', {'f': f})
urlpatterns = patterns('',
url(r'^$', 'account.views.index', name='index'),
url(r'^login/$', 'account.views.login', name = 'login'),
)
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^account/', include('account.urls')),
)
http://127.0.0.1:8000/login/
Answer the question
In order to leave comments, you need to log in
The error is here:
The "reverse" function searches by name, respectively, it should be like this:
Similarlyreverse('account.views.index')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question