0

I am running Django project at suburl like www.example.com/django . Everything is working fine but my static files are not working on this suburl since they the url they are taking is main like www.example.com/static/path_to_files but it should take the url as www.example.com/django/static/path_to_files.

This can be the case for other urls too because I think whenever I use any url for any link it must take the hostname with the suburl like www.example.com/django instead of www.example.com .

you can also see this question of mine for more information about server configuration files.

Community
  • 1
  • 1
Inforian
  • 1,716
  • 5
  • 21
  • 42

3 Answers3

0

In settings.py try:

STATIC_URL = '/django/static/'

More information here: https://docs.djangoproject.com/en/dev/howto/static-files/

aldo_vw
  • 608
  • 6
  • 17
0

You can serve them manually during development by adding the lines to urls.py:

urlpatterns = patterns('',
    # Media files
    url(r'^media/(?P<path>.*)$',
        'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}
    ),

    # Static files
    url(r'^static/(?P<path>.*)$',
        'django.views.static.serve',
        {'document_root': settings.STATIC_ROOT, 'show_indexes': True}
    ),
)

Don't use this in production, and read the doc, its well explained.

e-nouri
  • 2,576
  • 1
  • 21
  • 36
0

Define MEDIA_URL and STATIC_URL in settings.py

MEDIA_URL = /django/media
STATIC_URL = /django/static

Then prepend this variable while defining url in templates:

<a href="{{ MEDIA_URL }}/path_to_media_file/">media</a>
<img src="{{ STATIC_URL }}/path_to_static_file" />

Now you can use these variables wherever you want to create urls.