I'm having the following issue: I have an app that requires a parameter to be passed at login so the url structure is like this -> http://baseURL.com/paramter/
where "parameter" is a variable that is matched later on from a database.
The project is working just fine except when the following scenario occurs: http://baseURL.com/paramter/home
where "home" is a view that requires the user to be logged in by @login_required so the project checks the login_url in settings.py file and tries to go there and then I get the following error:
NoReverseMatch at /parameter/home/
Reverse for 'login_view' with arguments '()' and keyword arguments '{}' not found.
LOGIN_URL = reverse_lazy('login_view')
def login_view(request, parameter):
url(r'^(?P<parameter>\w+)/$', 'myproject.apps.myapp.views.login_view'),
So how to pass that parameter if settings.py goes to the login view before the url config?
You can simply pass arguments to the reverse function as kwargs
LOGIN_URL = reverse_lazy('login_view', kwargs={'parameter': 'login_parameter'})
https://docs.djangoproject.com/en/dev/ref/urlresolvers/#reverse
Usually the login url does not belong into settings.py
. You just put it into your urls.py