I am using django 1.5
I am able to serve the files in production because it is being handled at the apache level. Here is my httpd.conf file:
<VirtualHost *:80>
WSGIScriptAlias / /home/membership/membership/wsgi.py
Alias /static/ "/home/membership/static/"
<Directory /home/membership/static>
Order deny,allow
Allow from all
</Directory>
<Directory "/usr/lib/python2.6/site-packages/django/contrib/admin/static/admin">
Order deny,allow
Allow from all
</Directory>
<Directory /home/membership/membership>
<Files wsgi.py>
Order deny,allow
Satisfy Any
Allow from all
</Files>
</Directory>
</VirtualHost>
This works fine in production because of the Alias /static/ "/home/membership/static/"
When I try and run the app in my local development environment I can't get it to serve static files I just get a page not found 404 error. I am guess that this is because when I develop locally the requests are going straight to the development server since apache is not being used.
I do have a file at /static/me.png .
Is there somewhere that I am supposed to specify to serve static files in development?
When running python manage.py collectstatic
it seems to collect only the static files for the admin app. I have a file directly in the /app/static directory that I am trying to serve.
If you're Serving static files during development
On your settings.py file:
# Add it on your settings.py file
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"), # your static/ files folder
]
Example:
On your root urls.py file:
# add these lines
from django.conf import settings
from django.conf.urls.static import static
# Add +static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Example:
This is not suitable for production use! See more: https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-during-development
For media files on media/ directory: https://docs.djangoproject.com/en/dev/howto/static-files/#serving-files-uploaded-by-a-user-during-development
Did you define the path to your static files in your site's settings? I don't mean the url /static/
, I mean the STATICFILES_DIR
(it's what tells your devserver where the static files are just like the config file tells the apache
)
It's really best to just follow the documentation, it is absolutley fantastic:
Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With