我想在我的一个Django项目中尝试django-directupload,但我是Django的新手并且在安装方面遇到了一些麻烦。我正在遵循自述文件中的安装说明。我使用sudo pip install django-directupload
安装了django-directupload。
这是我的urls.py,我认为不对:
from django.conf.urls.defaults import patterns, include, url
from testproject import settings
import directupload
from django.contrib import admin
directupload.admin.patch_admin()
admin.autodiscover()
urlpatterns = patterns('testproject.database.views',
url(r'^(\d+)/$', 'test_view', name="test_page"),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^directupload/', include(directupload.urls))
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
修改
所以我已经深入了解了重写管理模板(感谢ilvar的链接)。我将contrib/admin/templates/admin/change_form.html
文件复制并粘贴到/admin/nameofmyapp/
子目录中的项目模板目录中,并在其余加载标记下方添加了{% load directupload_tags %}{% directupload_head %}
。当我去Django管理员时,我在'module' object has no attribute 'admin'
的第6行得到例外:urls.py
。
答案 0 :(得分:0)
答案 1 :(得分:0)
urls.py应如下所示:
from django.conf.urls.defaults import patterns, include, url
from testproject import settings
from directupload.admin import patch_admin
from django.contrib import admin
patch_admin()
admin.autodiscover()
urlpatterns = patterns('testproject.database.views',
url(r'^(\d+)/$', 'test_view', name="test_page"),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^directupload/', include(directupload.urls))
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
我的导入不正确。