Django 管理首页无法通过省略“admin”来正确构建模型 URL
我创建了一个应用程序(我们称之为“应用程序”),其中包含一些模型。我最近激活了管理页面,幸运的是它显示了应用程序下的所有模型。不幸的是,这些网址都是错误的。 url“/admin/app/modelX”实际上有效,但管理页面显示的url“/app/modelX”不包含“admin”。 我的 urls.py 有 (r'^admin/?', include(admin.site.urls)), 在 app 文件夹内,admin.py 的内容如下:
from smartctl.models import Model1, Model2, Model3, Model4, Model5 从 django.contrib 导入管理
类 Model1Admin(admin.ModelAdmin): 通过
admin.site.register(Model1, Model1Admin)
我查找了任何管理文件夹以了解它是如何生成这些网址的,但我找不到它(或它应该位于的“contrib”文件夹) 。我正在使用 django 测试服务器,版本 1.2.5。
I've created an app (let's call it "app") with some models under it. I recently activated the admin page, and fortunately it displays all the models under the app. Unfortunately, the urls are all wrong. The url "/admin/app/modelX" actually works, but the admin page presents the url "/app/modelX" without including "admin".
My urls.py has (r'^admin/?', include(admin.site.urls)),
Inside the app folder, admin.py is along these lines:
from smartctl.models import Model1, Model2, Model3, Model4, Model5
from django.contrib import admin
class Model1Admin(admin.ModelAdmin):
pass
admin.site.register(Model1, Model1Admin)
I've looked for any admin folder to find out how it is generating these urls, but I can't find it (or the "contrib" folder it is supposed to be under). I am using the django test server, version 1.2.5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现如果我输入管理网址为“.../admin/”,链接就会正确生成。正如你所看到的,我添加了一个“?”在 urls.py 中,以便“admin”和“admin/”被同等对待。不幸的是,这会在生成链接时导致不同的行为。
I found out that the link is generated correctly if I enter the admin url as ".../admin/". As you can see I included a "?" in urls.py so that "admin" and "admin/" were treated equivalently. Unfortunately, this results in different behavior when the links are generated.