Hi,

Which server are you using ? Is is runserver ?


When running in debug mode, it serves statics, but not when debug mode is 
turned off.

If you Google with "django runserver static debug" you'll get this hit in the 
very first ones :
https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail


The thread explains all the details and gives pointers to the reference 
documentation.


BTW, never use runserver in production. It is not done for that at all, for 
performances and security reasons.


Additionally, as explained in Django doc, statics should not be served by the 
Django app, but by the reverse proxy such as Nginx, which sits in front of the 
Django app and routes requests to the WSGI server, while serving directly 
static assets such as img, js, css...


An other option for statics if you don't want to dive too much into your 
reverse proxy settings for configuring the static routing is to use Django 
middlewares such as whitenoise (http://whitenoise.evans.io/en/stable/), which 
does a quite good job for static serving optimization. This should suffice for 
sites not too much demanding in terms of traffic.


Best regards


Eric

________________________________
From: [email protected] <[email protected]> on behalf 
of pujiarahman <[email protected]>
Sent: Monday, December 10, 2018 3:28:19 AM
To: Django users
Subject: Django in Linux set image

Hi all,

i have instaled django in ubuntu,
i have image and i put in folder (img), the locate is

blog
urls.py
views.py
admin.py
--------------static
---------------------- blog
-----------------------------dist
-----------------------------------img

When i load my browser The image is fine no problem, the problem is when,
i config the settings.py  to :

DEBUG = False
ALLOWED_HOSTS = ['localhost', '27.0.0.1', 'xxx.xxx.xxx.xxx', '[::1]']

the image can not found, but when i set Debug to True , the image come back 
normal.
is there any miss in my config settings.py

this my home.html

{% load static %}
<!DOCTYPE html>
<html>
<head>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<li class="user-header">
<img src="{% static 'blog/dist/img/noc.jpg' %}" class="img-circle" alt="User 
Image">

<p>
NOC
<small>Member since Nov. 2018</small>
</p>
</li>
..............


Regards

Sidik


--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b30d6a2-c1e0-45fb-8722-3b38ed6fd062%40googlegroups.com<https://groups.google.com/d/msgid/django-users/7b30d6a2-c1e0-45fb-8722-3b38ed6fd062%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/VI1P193MB0432DDD00D4084DC21234D968CA50%40VI1P193MB0432.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.

Reply via email to