获取一个对象的Django管理URL [英] Getting Django admin url for an object
问题描述
< a href ={{object | admin_url}}....> ...< / a>
基本上我使用的URL反转功能的视图名称为 django.contrib.admin.views.main.change_stage'
reverse('django.contrib。 admin.views.main.change_stage',args = [app_label,model_name,object_id]
url。
正如你可能已经猜到的,我试图更新到最新版本的Django,这是我遇到的障碍之一,该方法获取管理员网址不再工作。
如何在django 1.0中执行此操作? (或者是1.1,因为我正在尝试更新到svn中的最新版本)。
一个类似的问题,我会尝试调用 reverse('admin_index')
并且不断获得 django.core.urlresolvers.NoReverseMatch
错误。
原来,我的urls.py文件中有旧的格式的管理URL。
我在我的urlpatterns中有这个:
(r'^ admin /(.*)',admin.site.root)
这样可以让管理员屏幕正常工作,但这是不赞成的做法。我需要将其更改为:
(r'^ admin /',include(admin.site.urls)),
一旦我这样做了,所有在反向管理员网址文档开始工作。
Before Django 1.0 there was an easy way to get the admin url of an object, and I had written a small filter that I'd use like this: <a href="{{ object|admin_url }}" .... > ... </a>
Basically I was using the url reverse function with the view name being 'django.contrib.admin.views.main.change_stage'
reverse( 'django.contrib.admin.views.main.change_stage', args=[app_label, model_name, object_id] )
to get the url.
As you might have guessed, I'm trying to update to the latest version of Django, and this is one of the obstacles I came across, that method for getting the admin url doesn't work anymore.
How can I do this in django 1.0? (or 1.1 for that matter, as I'm trying to update to the latest version in the svn).
I had a similar issue where I would try to call reverse('admin_index')
and was constantly getting django.core.urlresolvers.NoReverseMatch
errors.
Turns out I had the old format admin urls in my urls.py file.
I had this in my urlpatterns:
(r'^admin/(.*)', admin.site.root),
which gets the admin screens working but is the deprecated way of doing it. I needed to change it to this:
(r'^admin/', include(admin.site.urls) ),
Once I did that, all the goodness that was promised in the Reversing Admin URLs docs started working.
这篇关于获取一个对象的Django管理URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!