Question

Why Nginx add query string ?next= to my django url path

Hi. i followed digitalocean tutorial at https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04

my view use @login_required

everythings fine when i start server with command

(env)$ python manage.py runserver 0.0.0.0:8000 and (env)$ gunicorn --bind 0.0.0.0:8000 lskweb.wsgi

In final step… Nginx proxy pass to gunicorn. but when i logged in , django will redirect to /?next=/home

urls.py

from central import views as c_view
from django.contrib.auth import views as auth_views
from django.urls import include, path

urlpatterns = [
    path('login/', auth_views.LoginView.as_view(template_name='central/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(next_page='login'), name='logout'),
    path('home/', c_view.home, name='home'),
    ]

central/views.py

@login_required
def home(request):
    data = {}
    return render(request, 'central/home.html', data)

central/templates/central/home.html

<h1>Home</h1>
  <a href="/logout">Logout</a>
  <hr>
  <h3><a href="/mails">Mails</a></h3>
  <h3><a href="/insure">Insure</a></h3>
  <h3><a href="/redbooks">Redbooks</a></h3>
  <h3><a href="/dshop">Dshop</a></h3>

=====

I removed @login_required from def home Nginx not add query string ?next= yet, but not my purpose becuse i want to secure my views

this is my django webapp link

Thank you.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer