1

Django 的文档提供了一种安装admin应用程序的简单方法。它假定文件结构如下:

mysite/
    manage.py
    mysite/
          settings.py #adding `admin` under `INSTALLED_APPS`
          __init__.py
          urls.py #adding urls
          wsgi.py
    myapp/
    __init__.py
    admin.py #creating this file
    models.py
    views.py 

admin如果我的结构如下,我的问题是如何让界面工作:

mysite/
      manage.py
      settings.py
      __init__.py
      urls.py
      myapp/
          __init__.py
          forms.py
          models.py
          views.py

admin为了使界面正常工作,我必须进行哪些更改。[我的其他应用程序正在运行]。我已经多次阅读文档。我正在使用Django 1.4.

编辑#1

我在运行时遇到此错误localhost:8000/admin/

error at /admin/
unknown specifier: ?P[

整个错误在这里

我的urls.py文件有以下行[如文档中所示]:

from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
    (r'^admin/(.*)', include(admin.site.urls)),
)

admin.pymyapp文件夹中的文件有代码:

import models
from django.contrib import admin

class PostAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}

admin.site.register(models.Article, PostAdmin)
4

1 回答 1

1

This is how you're supposed to include the admin urls:

url(r'^admin/', include(admin.site.urls)),

The documentation shows this.

The error that you're getting is coming straight from the re python module, complaining about this part of a url:

?P[

The URLs you've posted in your comment beneath show this:

url(r'^(?P[-a-zA-Z0-9]+)/?$', 'myapp.views.getPost')

Try changing that url by giving the match group a name:

url(r'^(?P<slug>[-a-zA-Z0-9]+)/?$', 'myapp.views.getPost')

And in your getPost view, include a slug argument.

于 2012-12-26T10:56:22.293 回答