django-staticfiles

STATIC_ROOT setup in Django 1.8

和自甴很熟 提交于 2019-12-04 20:57:11
I was tried n I can't set-up as per official documents... I am attaching IMG here, pls give me suggestions, Where is the problem. enter image description here Or, give me simple steps for it with dictionary tree structure. Thank you. # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static_root', 'static') STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), # '/var/www/static/', ) STATIC_ROOT = 'os.path.join(BASE_DIR, 'static_root', 'static') can't work. Try this : # define your

Load static files for all templates in django

会有一股神秘感。 提交于 2019-12-04 18:09:00
问题 Is there a way in django to not need the {% load static %} at the top of every template? This question indicates you can factor out common load tags into settings, but doesn't give the particulars you need in this case. 回答1: As of django 1.9, you can add the following to your template settings: 'builtins': ['django.contrib.staticfiles.templatetags.staticfiles'] For example, the whole template setting might look like this: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django

django 1.10 media images don't show

你离开我真会死。 提交于 2019-12-04 12:55:30
I have had django media images working in an existing django 1.7 project by adding the following to site urls.py: urlpatterns = patters( url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), ) This url structure doesn't work in django 1.10 and so I changed it to the reccommended here Django MEDIA_URL and MEDIA_ROOT : urlpatterns = [ ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) This fails to render any uploaded media images. Is there an equivalent media url patter for django 1.10 I can use? You can use this:

STATIC_URL Not Working After Django 1.5 Upgrade

寵の児 提交于 2019-12-04 05:14:53
问题 Im probably just tired and dont notice something obvious here but after upgrade to Django 1.5 the path to my static files is broken. settings.py from os.path import abspath, basename, dirname, join, normpath SITE_ROOT = dirname(dirname(abspath(__file__))) SITE_NAME = basename(SITE_ROOT) PROJECT_ROOT = dirname(SITE_ROOT) STATIC_ROOT = normpath(join(SITE_ROOT, 'static', 'site_media')) STATIC_URL = "/site_media/static/" STATICFILES_FINDERS = ( "staticfiles.finders.FileSystemFinder", "staticfiles

Django: How can I gzip staticfiles served in dev mode?

雨燕双飞 提交于 2019-12-04 05:11:14
My django.contrib.staticfiles settings seems to be ok as all static files get served as expected. However, eg. /static/*.css files do not get gzipped although I have GZipMiddleware turned on. Fyi. my views html actually does get gzipped, only the files served by the staticfiles app dont. Seems these responses dont go through the middleware chain? The trick is to have the development server run with the '--nostatic' flag set: ./manage.py runserver --nostatic . One then can user a url pattern for serving the static files like so: if settings.DEBUG: static_pattern = r'^%s(?P<path>.*)$' %

Using static files in custom 404/500 pages in Django

ぃ、小莉子 提交于 2019-12-04 04:02:40
I would like to use some custom CSS and images on my custom 404/500 pages that I made. Django doesn't include the STATIC_URL variable in those pages though. What would be the best way to accomplish this? I also tried making a custom 404/500 view and rendering an arbitrary HTML file but it didn't work out so great. Here's how I would do it: # urls or settings handler500 = 'mysite.views.server_error' # views from django.shortcuts import render def server_error(request): # one of the things ‘render’ does is add ‘STATIC_URL’ to # the context, making it available from within the template. response

Django : Static content not found

妖精的绣舞 提交于 2019-12-04 01:51:34
I have been breaking my head over this for a full day but can't figure out the problem. It happened after I copied my project from one machine to another. Settings.py STATIC_URL = '/static/' STATIC_ROOT = 'staticfiles' STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) Mentioned 'django.contrib.staticfiles' in INSTALLED_APPS as well. Folder structure : Django-Projects (root) project app static css home.css js manage.py Template : {% load staticfiles %} <link rel="stylesheet" href="{% static 'css/home.css' %}"> urls.py urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)),

Invalid block tag: 'static'

南笙酒味 提交于 2019-12-03 23:51:09
Server returned TemplateSyntaxError at / Invalid block tag: 'static' on this line: <img src="{% static 'icon/logo.png' %}"> . The whold html file is like this (it's an html file {% include %}ed by another one): {% load staticfiles %} <div class="header"> <nav> <ul class="nav nav-pills pull-right"> <li role="presentation"><a href="{% url 'offer rank' %}">潮品榜</a></li> <li role="presentation"><a href="{% url 'user rank' %}">达人榜</a></li> <li role="presentation"><a href="#" data-toggle="modal" data-target="#start">登陆</a></li> <li role="presentation"><a href="#" data-toggle="modal" data-target="

Files served unbearably slow from amazon s3

旧城冷巷雨未停 提交于 2019-12-03 16:38:33
I have a django app on heroku which serves the static files from amazon s3 bucket. I use boto library and followed the guide on the website. What can I do to speed up the file transfers? Some of the code: DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' AWS_ACCESS_KEY_ID = 'xxxx' AWS_SECRET_ACCESS_KEY = 'xxxx' AWS_STORAGE_BUCKET_NAME = 'boxitwebservicebucket' STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' STATIC_URL = 'http://' + AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/' the view class GetFileContent(View): def get(self,request, userName, pk): user = User

Faster alternative to manage.py collectstatic (w/ s3boto storage backend) to sync static files to s3?

旧城冷巷雨未停 提交于 2019-12-03 12:02:41
问题 I have been using s3boto's S3BotoStorage as my static files backend and syncing files to my aws s3 buckets (staging and production) using ./manage.py collectstatic. It works fine. However it is painfully slow. In addition to my own static files (just a few) and django admin, I have a few third party packages with many many static files (grappelli, django-redactor). And collectstatic can take upwards of 15 minutes each time I run it, depending on my internet connection. For instances where I'm