Image displayed on one machine, and another not in Django

0

I have an app in django that runs in two places, one at work, which is where there is effective production, and in my house, which is where I make adjustments because here I have time. The project is hosted on bitbucket and I always use the same version of the project, both at work and at home. The project runs perfectly in both environments, with one exception ... The version that runs in my house is not displaying an image that is in /static/img/ , the machine in my work is displaying normal (it runs on a debian server, with mod wsgi), and here at home runs on the same python server in linux deepin 15.5.

You have the {% load static%} at the top of the pages the image is showing, and the image path is like this:

<img src="{% static 'img/brasao.jpg' %}" widt="100" height="100"/><br>

Any idea why this is happening?

urls.py

from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include, url    

urlpatterns = [
url(r'^serf/', admin.site.urls),
#url(r'', admin.site.urls),
    url(r'^jet/', include('jet.urls', 'jet')),  # Django JET URLS
    url(r'^i/', include('cadastro.urls')),

urls.py (from inside the app folder)

from django.conf.urls import include, url
from .views import EmissaoTituloDetail
from .views import LaudoImovelDetail
from .views import ImovelDetail
from .views import NotificacaoDetail

urlpatterns = [
    url(r'^titulos/(?P<pk>\d+)/$', EmissaoTituloDetail.as_view(), 
name='emissao_titulo_detail'),
    url(r'^laudo/(?P<pk>\d+)/$', LaudoImovelDetail.as_view(), 
name='laudo_imovel_detail'),
    url(r'^encaminhamento/(?P<pk>\d+)/$', ImovelDetail.as_view(), 
name='encaminhamento_detail'),
    url(r'^notificacao/(?P<pk>\d+)/$', NotificacaoDetail.as_view(), 
name='notificacao_detail'),
]

settings.py

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
    
asked by anonymous 01.03.2018 / 05:48

1 answer

0

In development / production mode, Django will not really serve static files (since it expects this responsibility to be passed to an apache / nginx). But for ease, it still allows you to do it if necessary.

There in your urls.py you just need to do this:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Documentation link: link

    
03.03.2018 / 01:44