Image displayed on one machine, and another not on Django

Asked

Viewed 206 times

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 the adjustments because here I have time. The project is hosted in bitbucket and always use the same version of the project, both at work and at home. The design runs perfectly in both environments, with one exception... The version that runs in my house is not displaying an image that is in the /static/img/, on my work machine is displaying normal (there runs on a debian server, with mod wsgi), and here at home runs on the same python server on linux Deepin 15.5.

Is {% load Static %} at the top of the pages displaying the image, and the path of the image is like this:

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

Any idea why this is happening?

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')),

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'),
]

py Settings.

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

2 answers

0

I don’t know if it was a simple typo when you entered your code in the question, but there’s an "h" missing from the image tag:

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

the correct would be:

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

0

In development/production mode, Django will not actually serve the static files (since he expects this responsibility to be passed on to an apache/Nginx). But for ease’s sake, it still allows you to do so if necessary.

There in his urls.py you just have 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: https://docs.djangoproject.com/en/2.0/howto/static-files/#serving-Static-files-During-Development

  • Thanks for the help friend, it didn’t work here, when I put to copy the end of the image apparently it gives the correct path (http://localhost:8000/Static/img/brasao.jpg), and the image is in /Static/img/, but the image itself is not being displayed

  • In the terminal appears some 404 for that image?

  • yes, the 404 in the terminal, but the image is in the correct folder

  • You can edit your question and also put your own urls.py and the part of settings.py that has on the static archives?

  • add la amigo. has two urls.py files, a general one, and one inside the app folder, because of the doubts I put both, they are like before I made the change you suggested, but I put in both what you said and it did not work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.