Javascript with Django?

前端 未结 8 1269
日久生厌
日久生厌 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条回答
  •  长情又很酷
    2021-02-06 19:27

    I serve javascript via static. So I have something in my urls.py like

    (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': os.getenv('STATIC_DIR')})
    

    So JS urls look like /static/js/blah.js, CSS urls look like /static/css/blah.css, etc. I have Apache handle the static directory when running in production to avoid any issues with Django's static serving mechanism.

提交回复
热议问题