Django 1.4 admin static files without staticfiles app

吃可爱长大的小学妹 提交于 2019-12-02 17:36:56

问题


Django 1.4 release notes state:

If you're implicitly relying on the path of the admin static files within Django's source code, you'll need to update that path. The files were moved from django/contrib/admin/media/ to django/contrib/admin/static/admin/.

Could somebody explain how this is done exactly? Up to Django 1.3 we used ADMIN_MEDIA_PREFIX in settings.py, which is now deprecated. However, since we are developing all the time on our static files (js, css, ...), the staticfiles app is a rather annoying nogo for us. Calling collectstatic after each modification is a nightmare :-P

A pure Python/Django solution would be great. If that's impossible, we are using LighTPD as server and not Apache.


回答1:


manage.py collectstatic is used when you deploy, during development you can have django serve your static and media files by adding this to your url.py:

from django.conf.urls.static import static
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

...
...

if settings.DEBUG:
   # add one of these for every non-static root you want to serve
   urlpatterns+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
   # this take cares of static media (i.e. bundled in apps, and specified in settings)
   urlpatterns+= staticfiles_urlpatterns()

This will also serve all the static files that are bundled with reusable apps. This avoids the real nightmare of having to add symlinks to your webserver root for every third party app per project!




回答2:


Oops, I just found the solution in Django's new documentation:

https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/#serving-the-admin-files



来源:https://stackoverflow.com/questions/9967849/django-1-4-admin-static-files-without-staticfiles-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!