1👍
It looks like you don’t have a URL pattern for /static
. As such, the static/admin/css/base.css
URL doesn’t match any pattern, and so you get a 404. Try something like this:
from django.conf.urls.static import static
# ...
urlpatterns = patterns('',
# ...
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
# ...
This should work for you — go to /static/foo.css
, and you should see your CSS.
It’s worth noting that this is discouraged in a production environment. For your tutorial app, though, it’ll work.
0👍
The staticfiles app provides a custom runserver
management command that automatically serves the static files, are you sure you have the following in your settings?
INSTALLED_APPS = (
# ...
'django.contrib.staticfiles',
)
In production, you’ll use the collectstatic
management command that finds all of the static media and dumps it into STATIC_ROOT
(this is the only purpose for this setting – it isn’t used or needed during development).
- [Answer]-Django's ManyToManyField automatically adding a symmetric relationship between objects
- [Answer]-How to install paintstore for django
- [Answer]-Connection of 3 Models with Foreign Key
- [Answer]-Django annotate count doesn't seem to be counting
- [Answer]-Reference objects using foreign keys in Django forms
0👍
Glad you figured it out. Here’s why it works like this.
django.contrib.staticfiles
overrides the runserver
management command so that the static files are served automatically. To remind people that they shouldn’t be using django to serve static files, this only happens when DEBUG = True
, as you found out.
The documentation of the overridden management command explains that you can use the --insecure
flag to make this work no matter the state of the DEBUG
setting.
- [Answer]-Encoding in Django admin
- [Answer]-Inserting large amounts of data in Django via the shell
- [Answer]-Django send filepath to views.py
- [Answer]-How to add modelforms dynamically?
- [Answer]-Checking for contains in many-to-may field when doing a query in Django