Why can't STATIC_URL begin with 'http://' or '/' for a DJango dev server? -
Why can't STATIC_URL begin with 'http://' or '/' for a DJango dev server? -
recently i've been wanting add together load of functionality site. create process faster wanted serve static files off dev machine. specifically, wanted utilize built-in dev server ships django v1.3.1; modifying production server bad thought , having upload static files each time they're altered wasting lot of time , energy.
getting dev serve play ball has been nightmare! i've wasted 4 hours trying serve static info , turns out had wrong dev server doesn't appear '/' @ origin of static_url
? i'd know why and/or i'm doing wrong...
i've been trying utilize the settings suggested in docs either i've mis-read or there's more this.
my project looks this:
<project root> /app1 ..various files.. /app2 ..various files.. /static /style style.css /templates manage.py settings.py settings_dev.py settings_production.py urls.py
my settings.py
detects server we're running on , calls appropriate settings_dev.py
or settings_production.py
works , settings work fine on productions server.
my settings_dev.py
has following:
debug = true admins = ( ('jon', 'jon@mydomain'), ) databases = { 'default': { 'engine': 'django.db.backends.mysql', 'name': 'mydb', 'user': 'dbuser', 'password': 'dbpassword', 'host': '', 'port': '', } } media_root = '' media_url = '/media' static_root = 'c:/users/jon/pycharmprojects/myproject/static' static_url = 'http://192.168.1.4/static' staticfiles_dirs = () admin_media_prefix = 'http://192.168.1.4/static/admin/' template_dirs = ('c:/users/jon/pycharmprojects/myproject/templates',) is_production_server=false
..and urls.py
includes following:
from django.conf.urls.defaults import patterns, include, url django.conf import settings # uncomment next 2 lines enable admin: django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^$', 'app1.views.index'), (r'^/$', 'app1.views.index'), url(r'^admin/', include(admin.site.urls)), ) if settings.is_production_server false: print 'adding django static serving %s'%settings.static_root urlpatterns += patterns('', url(r'^static/(?p<path>.*)$', 'django.views.static.serve', { 'document_root': settings.static_root, }), )
this works in much templates pick static url , give me (for example) http://192.168.1.4/static/style/style.css
but if alter static_url
/static
...and visit http://192.168.1.4/static/style/style.css
404 error:
'\style\style.css' not found
so what's going on?
there special helpers route urls static files
from django.conf.urls.static import static django.contrib.staticfiles.urls import staticfiles_urlpatterns if settings.is_production_server false: urlpatterns += static(settings.media_url, document_root=settings.media_root) urlpatterns += staticfiles_urlpatterns()
also, never checked sources see if matters, in examples in original settings.py static_root,static_url,media_url , media_root end /, give try.
if you're in dispair, after many start of django projects forget set made generic purpose django base of operations project, can find @ https://github.com/riquito/semiautomatic-django-setup
django
Comments
Post a Comment