Home > other >  The correct django3.0 jump to the home page after login
The correct django3.0 jump to the home page after login

Time:09-25

According to "Python from entry to practice", input your user name password and then click the login error, which help to look at, I am 3.0.4 Django, Python version 3.8
Error:

NoReverseMatch ats/users/login/

Reverse for 'index' not found. 'index' is not a valid view function or the pattern name.

The Request Method: POST
The Request URL: http://127.0.0.1:8000/users/login/
Django Version: 3.0.4
The Exception Type: NoReverseMatch
The Exception Value:

Reverse for 'index' not found. 'index' is not a valid view function or the pattern name.

The Exception Location: D: \ Work \ python \ leaming_log \ ll_env \ lib \ site - packages, django, urls, resolvers. Py in _reverse_with_prefix, line 677
The Python Executable: D: \ Work \ Python \ leaming_log \ ll_env \ Scripts \ Python exe
Python Version: 3.8.0
Python Path:

[' D: \ \ Work \ \ python \ \ leaming_log ',
'C: \ \ Users \ \ Administrator \ \ AppData \ \ Local \ \ designed \ \ Python \ \ Python38 \ \ Python38 zip',
'C: \ \ Users \ \ Administrator \ \ AppData \ \ Local \ \ designed \ \ \ \ Python Python38 \ \ DLLs',
'C: \ \ Users \ \ Administrator \ \ AppData \ \ Local \ \ designed \ \ \ \ Python Python38 \ \ lib',
'C: \ \ Users \ \ Administrator \ \ AppData \ \ Local \ \ designed \ \ Python \ \ Python38',
'D: \ \ Work \ \ \ \ python leaming_log \ \ ll_env',
'D: \ \ Work \ \ \ \ python leaming_log \ \ ll_env \ \ lib \ \ site - packages']

Server time: Monday, March 16 2020 22:28:19 + 0800

Another post code:
The login. The HTML
 
{% extends "learning_logs/base. HTML" %}

{% block content %}

{% if form. Errors %}

Your username and password didn 't match. Both Please try again. & lt;/p>
Endif {% %}

{% csrf_token %}
{{form. As_p}}



{% endblock content %}



Learning_logs/views. Py
 
The from the django. Shortcuts import render
The from the django. HTTP import HttpResponseRedirect
# the from django. Core. Urlresolvers import reverse
The from the django. Urls import reverse

From the models import Topic, Entry
From the forms the import TopicForm, EntryForm

Def index (request) :
"" "learning notes page "" "
Return render (request, 'learning_logs/index. HTML)
.


Learning_logs/urls. Py
 
"" "define learning_logs url patterns "","

The from the django. Conf. Urls import url
The from the django. Urls import path

From the import views

App_name='learning_logs'
Urlpatterns=[
# page
Path (' views. The index, name='index'),
# url (r '^ $' views. The index, name=' index '),

# show all theme
# url (r '^ switchable viewer/$', views, switchable viewer, name=' switchable viewer '),
Path (' switchable viewer/' views. Switchable viewer, name='switchable viewer'),

# a particular theme detail page
# url (r '^ switchable viewer/? PPath (' switchable viewer/& lt; Topic_id & gt;/'views. The topic, the name=' topic '),

# to add a new theme page
# url (r '^ new_topic/$', views. New_topic, name=' new_topic '),
Path (' new_topic/' views. New_topic, name='new_topic'),

# to add a new entry page
# url (r '^ new_entry/? PPath (' new_entry/& lt; Topic_id & gt;/'views. New_entry, name=' new_entry '),

# to edit entry page
# url (r '^ edit_entry/? PPath (' edit_entry/& lt; The entry_id & gt;/'views. Edit_entry, name=' edit_entry '),
]

CodePudding user response:

Reverse for 'index' not found. 'index' is not a valid view function or the pattern name.


The index is a reserved word, cannot be used to do the function name

CodePudding user response:

reference 1st floor tianfang response:
Reverse for 'index' not found. 'index' is not a valid view function or the pattern name.
The index is a reserved word, cannot be used to do the function name

Should not the problem, I didn't do when logging jump is good, is to open the web site before the default is in the index. The HTML page, is that

CodePudding user response:

Form the action you use/users/login/

I use django 2.2, is available accounts/login/admin/login

CodePudding user response:

From the point of error, should be the login template page. The inside of the HTML {% url 'learning_logs: index' %} have problems
But you don't have the whole code complete, don't know where there is a problem, you can try to use the method to troubleshoot the problem, rather than put these pieces of code a wait for someone else to help you see
  • Related