Django serve static index.html with view at '/' url

后端 未结 5 2027
面向向阳花
面向向阳花 2020-12-25 11:14

I have my index.html in /static/ folder. My django app is running ok when i try:

http://127.0.0.1:8000/index.html

But i want to acces index

5条回答
  •  暖寄归人
    2020-12-25 11:50

    Check out my long explanation of how to serve index.html on / in this answer (or extended as a blog post). That solution alone might not be sufficient, however, if you want to have a full-fledged SPA served by Django (because you need frontend routing).

    I've been playing with different methods for routing /static/ to /, forwarding all requests to the frontend, finding index.html files. In the end I found the best method to solve all of this was not by tweaking urls.py, but as an extension of WhiteNoise that I released as django-spa (installation instructions in the README).

    You can find some of the related discussion in this WhiteNoise issue.

提交回复
热议问题