开发者

Django static files not loading with default setup

So I installed Bitnami Django stack, and enabled the admin module, and followed the tutorial for creating an admin menu for "Polls".

However, when I go to /admin/ everything is white plaintext. All the css and images are 404 error.

All I did was:

enable in settings.py installed_apps:

'django.contrib.admin',

In urls.py UNcommented:

from django.contrib import admin
admin.autodiscover()
url(r'^admin/', include(admin.site.urls)),

uncommented.

In settings.py, I tried using default settings and also tried this:

MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_ME开发者_如何学编程DIA_PREFIX = STATIC_URL + 'admin/'
import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATICFILES_DIRS = (
  os.path.join(SITE_ROOT, 'static/'),
)

Nothing seems to work, it refuses to find static files in /admin/media/css/ etc.

I made sure my windows PATH has /bin of django. I even tried including /contrib, nothing helps.

I have installed Django to: C:\DjangoStack\apps\django

I have installed my project to: C:\Users\dexter\BitNami DjangoStack projects\Alpha and I type: localhost/Alpha/admin to go to admin.


I almost missed the answer to this until I re-read your question and finally caught the bit in the last line: "and I type: localhost/Alpha/admin to go to admin". That means all your URL settings are wrong.

Currently, you have:

MEDIA_URL = '/media/'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

Whereas, these should be:

MEDIA_URL = '/Alpha/media/'
STATIC_URL = '/Alpha/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

Additionally, you don't need "static/" in STATICFILES_DIRS. So remove that setting.


I'm from the BitNami Team and I just saw this issue. I'm not sure if you are using and older version but at least in the newer version of the BitNami DjangoStack you just need to make sure that the ADMIN_MEDIA_PREFIX point to /static/admin/ if you are following the instructions in https://docs.djangoproject.com/en/1.3/intro/tutorial02/ . You don't need to copy the static files in your project directory because django automatically will use the files in django/contrib directory.

However currently we are setting the ADMIN_MEDIA_PREFIX to /static/admin/media because the behavior is different when the application is served by Apache instead of the django server. We realize that this may be a bit confusing for users that are just starting with django and we are looking at this on our side to keep the default configuration for the new projects but also allow the demo project to be served by Apache.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜