django-staticfiles

django - Server error loading static files

泪湿孤枕 提交于 2019-12-01 22:58:28
So im building my own django site. Right now im stuck with loading the statics. im getting the following error in the console: GET http://localhost:8000/static/css/style.css 500 (Internal Server Error) Im trying to load a css file using the static taggs: {{ STATIC_URL }} in my settings i've edited the following: PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) STATIC_ROOT = os.environ.get('STATIC_ROOT',os.path.join(PROJECT_ROOT,"static",)) STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, "static",), ) also added the TEMPLATE_CONTEXT_PROCESSORS: TEMPLATE_CONTEXT

Django Nginx Browser Caching Configuration

做~自己de王妃 提交于 2019-12-01 21:37:11
I am trying to configure Nginx to leverage on static file caching on browser. My configuration file is as following server { listen 80; server_name localhost; client_max_body_size 4G; access_log /home/user/webapps/app_env/logs/nginx-access.log; error_log /home/user/webapps/app_env/logs/nginx-error.log; location /static/ { alias /home/user/webapps/app_env/static/; } location /media/ { alias /home/user/webapps/app_env/media/; } ... } When I add in the following caching configuration, the server fails to load static files and I am not able to restart my Nginx. location ~* \.(jpg|jpeg|png|gif|ico

how to serve static files in django development server

假如想象 提交于 2019-12-01 13:02:32
this question has been answered several times and i have seen almost all related posts,but couldn't get css files load. i have this structure in my project: mysite /templates /settings.py /urls.py /myapp /static /css /test.css in settings.py i have this code: import os PROJECT_PATH=os.path.realpath(os.path.dirname(__file__)) STATIC_ROOT = os.path.join(PROJECT_PATH,'static',) STATIC_URL = '/static/' in urls.py i have this code: from django.conf.urls.defaults import* from mysite.myapp.views import test urlpatterns = patterns('',(r'^home/$',test),) from django.conf import settings if settings

Django: STATIC_URL adds appname to the url

落爺英雄遲暮 提交于 2019-12-01 11:03:34
I have configured my static settings like so: STATIC_ROOT = os.path.join(SITE_ROOT, 'static') STATIC_URL = '/static/' STATICFILES_DIRS = ( ('js', os.path.join(STATIC_ROOT, 'js')), ('css', os.path.join(STATIC_ROOT, 'css')), ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) and these in my urls.py : urlpatterns = patterns('', url(r'^login/?$', login, name='login'), url(r'^logout/?$', logout_then_login, name='logout'), url(r'^profile/(?P<user_id>

how to serve static files in django development server

雨燕双飞 提交于 2019-12-01 10:46:30
问题 this question has been answered several times and i have seen almost all related posts,but couldn't get css files load. i have this structure in my project: mysite /templates /settings.py /urls.py /myapp /static /css /test.css in settings.py i have this code: import os PROJECT_PATH=os.path.realpath(os.path.dirname(__file__)) STATIC_ROOT = os.path.join(PROJECT_PATH,'static',) STATIC_URL = '/static/' in urls.py i have this code: from django.conf.urls.defaults import* from mysite.myapp.views

Django: STATIC_URL adds appname to the url

流过昼夜 提交于 2019-12-01 10:07:46
问题 I have configured my static settings like so: STATIC_ROOT = os.path.join(SITE_ROOT, 'static') STATIC_URL = '/static/' STATICFILES_DIRS = ( ('js', os.path.join(STATIC_ROOT, 'js')), ('css', os.path.join(STATIC_ROOT, 'css')), ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) and these in my urls.py : urlpatterns = patterns('', url(r'^login/?$',

Heroku static files not loading, Django

China☆狼群 提交于 2019-12-01 01:47:46
I'm trying to push my Django project to Heroku, but it isn't loading the staticfiles. I used this to setup the things, everything is fine but I'm not able to fix the issue with static files. My directory structure is like this help_the_needy help_the_needy __init__.py settings.py urls.py views.py wsgi.py manage.py Procfile requirements.txt static css font-awesome fonts img js templates base.html display_list2.html index.html Here is the complete code (all files). This is my settings.py. I tried alot of things to fix this, but nothing seems to work. When I push it does copy static files but it

django dev server, adding headers to static files

杀马特。学长 韩版系。学妹 提交于 2019-11-30 13:11:04
Using the django dev server (1.7.4), I want to add some headers to all the static files it serves. It looks like I can pass a custom view to django.conf.urls.static.static , like so: if settings.DEBUG: from django.conf.urls.static import static from common.views.static import serve urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT, view=serve) And common.views.static.serve looks like this: from django.views.static import serve as static_serve def serve(request, path, document_root=None,

Django serve static index.html with view at '/' url

家住魔仙堡 提交于 2019-11-30 04:41:30
I have my index.html in /static/ folder. My django app is running ok when i try: http://127.0.0.1:8000/index.html But i want to acces index.html by url: http://127.0.0.1:8000/ I wrote a view and it works: class IndexView(TemplateView): template_name = 'index.html' I also added to urls.py(this lets me serve static like http://127.0.0.1:8000/css/style.css ): url(r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve', { 'document_root': settings.STATIC_ROOT, 'show_indexes':True }), But i think there is a way to do what i want without TemplateView. Any suggestions? Thanks. My django version

how to point correctly to static image in django

倖福魔咒の 提交于 2019-11-30 04:09:34
I have a template that renders an image: {% load staticfiles %} <img src="{% static "img/logo.png" %}" alt="My image"/> The image link is broken, but it points to: localhost/static/img/logo.png What are values I need to set for static_root, static_url, and STATICFILES_DIRS to get this image to show up correctly? This is my directory structure: myprojectname (top level) --- myprojectname --- --- myproectname --- --- --- settings --- --- --- --- base.py (setting.py) --- --- static --- --- --- img This is my static configuration in settings: STATIC_ROOT = '/Users/myuser/myprojectname