2

In my settings.py,

STATIC_ROOT = '/home/khantthulinn/webapps/static_media/'
STATIC_URL = '/home/khantthulinn/webapps/static_media/'

In my urls.py,

urlpatterns = patterns('',

    url(r'^admin/', admin.site.urls),

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

)+ static(settings.STATIC_ROOT, document_root=settings.STATIC_ROOT)

After that, in my web server, I have copied static files.

python manage.py collectstatic

Everything is okay and I see all correctly.

It become problem when I change DEBUG = False.

I read this already but I don't understand.

https://docs.djangoproject.com/en/1.10/howto/static-files/deployment/

I have read solution from here too.

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

With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that.

I wana try that. How shall I do?

I don't want to run this since it is insecure.

manage.py runserver --insecure
Community
  • 1
  • 1
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

2 Answers2

1

You have to create an alias for /static to the path where they are locally. Read this answer:

Django Static File Hosting an Apache

Community
  • 1
  • 1
KVISH
  • 12,923
  • 17
  • 86
  • 162
0

if you're using apache with mod_wsgi, you'll need to change your wsgi.py file.

all you need to insert are those lines at the end of your file:

from django.core.wsgi import get_wsgi_application from django.contrib.staticfiles.handlers import StaticFilesHandler application = StaticFilesHandler(get_wsgi_application())

Note that I'm using Django 1.8(LTS) and I'm not quite sure if those functions are still in the actual version.

Philipp Zettl
  • 177
  • 1
  • 3
  • 17