django Page Jump Problems and Points for Attention

  • 2021-07-22 10:47:07
  • OfStack

1. Page jump

urls of the project:


urlpatterns = [
 url(r'^app/', include(('app.urls'),namespace='my_app')),
]

urls for app:


urlpatterns = [
 # Home page 
 url(r'^index/',views.my_home,name='my_index'),
]

How can I jump to the home page if I log in successfully?


return HttpResponseRedirect( ' /app/index/')
return HttpResponseRedirects(reverse( ' my_app:my_index'))

Note: return Response(response,'home.html'), Just opened a new page, not a jump.

2. Problems encountered: After logging in successfully, the page jumps to the home page, but url does not change.

Error cause: Will return HttpResponseRedirect(‘/app/index/') The address in is written as app/index/. The preceding/should not be left out.

3. When you want to click the navigation bar to jump to the corresponding page


<a href="{% url 'my_app:my_index' %}" rel="external nofollow" > Home page </a>

Summarize


Related articles: