Javascript with Django?

前端 未结 8 1271
日久生厌
日久生厌 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:30

    This is a structure I use in a project separated into multiple apps. It's a good practice to adapt this structure right at the start -- you don't want global rearrangement when you need to add another app to your project.

    /media
      favicon.ico
      robots.txt
      /upload # user uploaded files
      /js  # global js files like jQuery
      /main_app
        /js
        /css
        /img
      /other_app
        /js
        /css
        /img
    

    Then I use excellent StaticMiddleware from django-annoying to serve files. settings.py:

    import os
    import annoying
    
    MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media")
    MIDDLEWARE_CLASSES = (
        'annoying.middlewares.StaticServe',
        #...
    )
    

提交回复
热议问题