django-staticfiles

Django get the static files URL in view

懵懂的女人 提交于 2019-11-26 12:35:39
问题 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\" 回答1: Since this is the top result on Google, I thought I'd add another way to do this

Difference between static STATIC_URL and STATIC_ROOT on Django

谁说我不能喝 提交于 2019-11-26 07:55:46
问题 I am confused by static root and want to clarify things. To serve static files in Django, the following should be in settings.py and urls.py : import os PROJECT_DIR=os.path.dirname(__file__) 1. Absolute path to the directory in which static files should be collected STATIC_ROOT= os.path.join(PROJECT_DIR,\'static_media/\') 2. URL prefix for static files STATIC_URL = \'/static/\' 3. Additional locations for static files STATICFILES_DIRS = ( os.path.join(PROJECT_DIR,\'static/\'),) ...and in urls

django 1.5 - How to use variables inside static tag

纵然是瞬间 提交于 2019-11-26 03:52:13
问题 I\'m currently migrating all the static files references in my project to the new {% static %} tag that django 1.5 introduced, but I\'m having a problem, in some places I use variables to get the content. With the new tag I can\'t, is there any way to solve this? Current code: <img src=\"{{ STATIC_URL }}/assets/flags/{{ request.LANGUAGE_CODE }}.gif\" alt=\"{% trans \'Language\' %}\" title=\"{% trans \'Language\' %}\" /> What it should be (this doesn\'t work): <img src=\"{% static \'assets

Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT

故事扮演 提交于 2019-11-26 03:48:47
问题 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

Why does DEBUG=False setting make my django Static Files Access fail?

会有一股神秘感。 提交于 2019-11-26 01:25:23
问题 Am building an app using Django as my workhorse. All has been well so far - specified db settings, configured static directories, urls, views etc. But trouble started sneaking in the moment I wanted to render my own beautiful and custom 404.html and 500.html pages. I read the docs on custom error handling, and set necessary configurations in UrlsConf, created corresponding views and added the 404.html and the 500.html to my app\'s template directory (specified in the settings.py too). But the