Source code url(r'codeedit$', views.index, name='index') Run ▶ For example, to www.mysite.com/codedit you must have the following url code: But how do I get to the following url only when I log in?
codeedit$',I looked it up and found in Django docs
Source code django.contrib.auth.views.login Run ▶ The following code is
Source code url(r'$', django.contrib.auth.views.login), Run ▶ It is said that it is possible to use it with , but if you use it like this, you cannot call views.index. Is it possible to write all together in one line?
$', django login
1) Once the user is not logged in, the link to www.mysite.com/codeedit should not be displayed. I think you can handle this part in the views and templates that http://www.mysite.com is connected to.
2) Can the user still type www.mysite.com/codeedit and enter immediately? In that case, in the index,
def index(request):
if not request.user.is_authenticated():
return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
You can do this. Or you can show an error message instead of redirect.
Alternatively,
@login_required
def index(request):
#Doing something
If this does not automatically log in, settings.Redirect to LOGIN_URL.
Both methods set in advance.You need to set the LOGIN_URL.
© 2024 OneMinuteCode. All rights reserved.