Javascript with Django?

前端 未结 8 1369
日久生厌
日久生厌 2021-02-06 19:20

I know this has been asked before, but I\'m having a hard time setting up JS on my Django web app, even though I\'m reading the documentation.

I\'m running the Django de

8条回答
  •  萌比男神i
    2021-02-06 19:24

    You may want to use absolute path for 'document_root' in urls.py if you want to use the development server to serve static files. MEDIA_ROOT and MEDIA_URL don't play any role here.

    Here are my settings for your reference. I put all static media files under site_media/

    mysite/
        site_media/
            css/
            js/
            images/
        ...
    

    in settings.py:

    ROOT_PATH = os.path.normpath(os.path.dirname(__file__))
    

    in urls.py:

    url(r'^media/(?P.*)$', "django.views.static.serve", {'document_root':
                                          os.path.join(settings.ROOT_PATH, 'site_media')})
    

    You can move static files else where, just need to point 'document_root' to the correct path. Make sure comment out this url line for production deployment.

提交回复
热议问题