我能否使用编外用户在 /admin
上登录的登录网页?
LOGIN_URL = /admin/
LOGIN_REDIRECT_URL = /
当我登录时,它并没有将我引向根文件夹。 我这样做是对的吗?
注:我在我看来使用装饰符
< 强力 > 编辑 < /强 >
它用这个网址把我登录到行政网站: http://127.0.0.1:800/admin/?next=/
我能否使用编外用户在 /admin
上登录的登录网页?
LOGIN_URL = /admin/
LOGIN_REDIRECT_URL = /
当我登录时,它并没有将我引向根文件夹。 我这样做是对的吗?
注:我在我看来使用装饰符
< 强力 > 编辑 < /强 >
它用这个网址把我登录到行政网站: http://127.0.0.1:800/admin/?next=/
编外人员无法通过管理员视图登录,所以无法登录。
然而,Django认为,这恰恰符合你需要: django.contrib.auth.views.login
。
您可以很容易地将其添加到您的 urlconf
:
from django.contrib.auth.views import login
urlpatterns = ( ,
#snip
url(r ^login/$ , login)
)
您只需要定义一个视图的模板, 默认情况下, 只需在 < code> registration/ login.html code> 上找到该模板, 但该模板会被覆盖 。
<强> UPDATE 强>
1) 配对1.11+更好地使用LoginView (即来自django.contrib.auth.views的 导入LoginView
),因为“code>login 代码实际上使用了LoginView和代码(
login
),甚至有一个警告:
warnings.warn( The login() view is superseded by the class-based LoginView(). , RemovedInDjango21Warning, stacklevel=2 )
2) 您可能想要更改 admin s 登录页的默认页头。 可以通过在上下文中提供 < code> site_ header 来做到这一点。
因此,更新版将看起来是这样的:
from django.contrib.auth.views import LoginView
urlpatterns = [
# your patterns here,
url(r ^login/$ ,
LoginView.as_view(
template_name= admin/login.html ,
extra_context={
site_header : My custom header ,
})),
]
With Django 1.6 I was able to use django s own admin login template with the following setup. Then when I open / it will redirect me to the login screen, and after logging in it sends me back to /
<强力 > 设置。 py 强 >
INSTALLED_APPS = (
django.contrib.admin ,
django.contrib.auth ,
django.contrib.contenttypes ,
django.contrib.sessions ,
django.contrib.messages ,
django.contrib.staticfiles ,
core ,
south ,
)
LOGIN_URL = /login
<强>urls.py 强>
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib.auth.views import login
admin.autodiscover()
urlpatterns = patterns(
,
url(r ^ , include( core.urls )),
url(r ^admin/ , include(admin.site.urls)),
url(r ^login/$ , login, { template_name : admin/login.html })
# I didn t create this admin/login.html template
# Django will use the one from the admin application ;-)
)
<强度 > 核心/极核.py 强 >
from django.conf.urls import patterns, url
urlpatterns = patterns(
core.views.web_views ,
url(r ^$ , home ),
)
<强度 > 核心/视图/网视图。 py 强 >
from django.shortcuts import render_to_response
from django.template.context import RequestContext
__author__ = tony
from django.contrib.auth.decorators import login_required
@login_required
def home(request):
return render_to_response( home.html , {}, context_instance = RequestContext(request))
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...
Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...
Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...
I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...