I am new to stackoverflow and django ...
A short question (see the “long question” below), the following code in the myapps / views.py file did not execute:
from django.core.urlresolvers import reverse ... @login_required(login_url=reverse('django.contrib.auth.views.login')) def my_view(request): pass
Mistake:
ViewDoesNotExist at / tried my-view2 in module myproject.myapps.views. Error was: 'module' object has no attribute 'my-view2'
'my-view2' is defined in myapps / views.py after my-view (and refers to myproject / urls.py)
I suppose there is something like chicken and eggs here, but I can't figure out where I am going wrong. I am trying to set LOGIN_URL in settings.py, as with the same error:
from django.core.urlresolvers import reverse ... LOGIN_URL=reverse('django.contrib.auth.views.login')
Now a long question (what context, why I want to do this):
Working with django 1.3.1 I got the following view protected by auth.decorator:
@login_required def my_view(request) pass
This decorator redirects to / accounts / login by default (it works and works for me).
Using the development server, all URLs refer to localhost: /
On the production server (using wsgi), all the URLs refer to my server: / path1 / This is due to the apache configuration, which says something like: WSGIScriptAlias / path1 / var / www / path / to / script.wsgi
And that is good for me.
All URLs defined in myproject / urls.py automatically correspond to this new path, so thanks to django my whole site is working on this new "html root".
But my protected view is still being redirected to my server: / accounts / login / instead of o my-server: / path1 / accounts / login
so far i am working using settings.py
LOGIN_URL=/path1/accounts/login/
or using the login_url parameter in the login_required window:
@login_required(login_url="/path1/accounts/login/")
But I would like this login window to be relative to the entire site path without setting "path1" in apache and django / settings.py
I don't think using reverse in settings.py is the right thing. and also do not use it in the decorator. But so far I don’t know how to handle this ...