Python

From Mosuma
Jump to: navigation, search

Advocacy

Django

Schema Migration

./manage.py schemamigration APPNAME --auto
./manage.py migrate APP


Serving Static Files


manage.py runserver
wsgi
settings.DEBUG
True

settings.STATIC_ROOT
os.path.join(DIRNAME, 'static')
os.path.join(DIRNAME, 'static')
settings.STATIC_URL
/static/
/static/
settings.STATICFILES_DIRS
{absolute path to files}
BLANK

url.py

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()


url.py

Solution 1 for /media

if settings.DEBUG
     urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)


url.py

Solution 2 for /media

if settings.DEBUG
     urlpatterns += patterns(, url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes':True}),)


Serving Media Files