django-staticfiles

Django and service workers - serve “sw.js” at application's root url

冷暖自知 提交于 2019-11-27 03:25:22
问题 So I'm building a Django progressive web app with offline support using service workers. According to google's documentation, the sw.js file should be at the root of the app's url: You need to do this because the scope of a service worker (the set of urls that the ServiceWorker will load for) is defined by the directory where it resides. At the moment, I'm serving all static assets from http://example.com/static/ folder. But I need to serve this specific file at a url like: http://example.com

Django get the static files URL in view

纵饮孤独 提交于 2019-11-27 02:51:52
I'm using reportlab pdfgen to create a PDF. In the PDF there is an image created by drawImage . For this I either need the URL to an image or the path to an image in the view. I managed to build the URL but how would I get the local path to the image? How I get the URL: prefix = 'https://' if request.is_secure() else 'http://' image_url = prefix + request.get_host() + STATIC_URL + "images/logo_80.png" Since this is the top result on Google, I thought I'd add another way to do this. Personally I prefer this one, since it leaves the implementation to the Django framework. # Original answer said:

Django runserver not serving static files in development

我是研究僧i 提交于 2019-11-27 02:38:46
问题 I am using Django with runserver for my development. When I deploy to my production server I can see all my static files, but not on my local computer. I did collectstatic and I have set DEBUG = True . I found many different opinions online, the most prominent being the STATICFILES_DIRS , but that does not work for me. How can I set it so that in my development environment I can see the static files, and when I upload my files to the server I do not need to make any changes for the production

Where is template context processor in Django 1.5?

前提是你 提交于 2019-11-27 02:07:19
问题 Is it supposed to be listed in Settings.py automatically or do I have to add it? I am having a ridiculously hard time serving up an image file in development and the docs are too terse for my taste and don't spell things out clearly to me for some reason. I'd like to check to see what my template_context_processors are, but where is it located? It's not in my settings.py file. Do I need to edit this typically? ("django.contrib.auth.context_processors.auth", "django.core.context_processors

Django StaticFiles and Amazon S3: How to detect modified files?

北城以北 提交于 2019-11-27 02:00:35
问题 I'm using django staticfiles + django-storages and Amazon S3 to host my data. All is working well except that every time I run manage.py collectstatic the command uploads all files to the server. It looks like the management command compares timestamps from Storage.modified_time() which isn't implemented in the S3 storage from django-storages. How do you guys determine if an S3 file has been modified? I could store file paths and last modified data in my database. Or is there an easy way to

ValueError: Missing staticfiles manifest entry for 'favicon.ico'

五迷三道 提交于 2019-11-27 01:35:27
问题 I'm getting a ValueError when running python manage.py test . My project is named fellow_go , and I'm currently working on an App called pickup . Please note that this error is added in a relatively recent commit to Django: Fixed #24452 -- Fixed HashedFilesMixin correctness with nested paths.. ====================================================================== ERROR: test_view_url_exists_at_desired_location (pickup.tests.test_view.HomePageViewTest) -----------------------------------------

Django static files on heroku

北慕城南 提交于 2019-11-27 01:26:38
问题 I deployed a django app to heroku, using "git push heroku master" which worked absolutely fine. I then created a second app on the same git using "heroku create second-app -r staging' and pushed using: git push staging master when I open second-app, none of the static files are picked up or loaded (ie no css, js, or images work) This is extremely confusing - please help! my settings file is below import os import platform import dj_database_url DEBUG = True TEMPLATE_DEBUG = DEBUG # This

Can I make STATICFILES_DIR same as STATIC_ROOT in Django 1.3?

可紊 提交于 2019-11-27 00:21:05
问题 I'm using Django 1.3 and I realize it has a collectstatic command to collect static files into STATIC_ROOT . Here I have some other global files that need to be served using STATICFILES_DIR . Can I make them use the same dir ? Thanks. 回答1: No. In fact, the file django/contrib/staticfiles/finders.py even checks for this and raises an ImproperlyConfigured exception when you do so: "The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting" The STATICFILES_DIRS can contain other

Django staticfiles not found on Heroku (with whitenoise)

懵懂的女人 提交于 2019-11-26 14:36:21
问题 This question seems to be asked several time but I can not fix it. I deployed a django app on production with DEBUG = False . I set my allowed_host . I used {% load static from staticfiles %} to load static files. I exactly write the settings sugested by Heroku doc : BASE_DIR = os.path.dirname(os.path.dirname(__file__)) PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join

Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT

我与影子孤独终老i 提交于 2019-11-26 14:08:49
What are the differences of these three static url? I am not sure if I am right, I am using the MEDIA_ROOT to store my uploaded photos (via models.ImageField() ) However, I created a JS script to my admin and in admin.py . I defined the media as below: .... class Media: js = ('/admin/custom.js', ) and my settings.py : .... STATIC_ROOT = "/home/user/project/django1/top/listing/static" and I added the custom.js to STATIC_ROOT/admin/custom.js , but it is not working. Throwing 404 not found error. And then I change the STATIC_ROOT to STATICFILES_DIRS , and it works!! .... STATICFILES_DIRS = "/home