How to serve another static root in Django for html pages?









up vote
0
down vote

favorite












The typical configuration serves two static roots:



http://www.example.org/static/
http://www.example.org/media/


This is STATIC_URL and MEDIA_URL.



I would like to add a third one to host static files build with Sphinx:



http://www.example.org/docs/


I know I could configure this on the level of the web server. Is it also possible to configure this on the level of Django?



Here is my python package, that implements Sphinx with Django templates and renders it to static pages. A kind lightweight read-the-docs. Still in an early state, yet working.



https://github.com/elmar-hinz/Django.SphinxCMS










share|improve this question



























    up vote
    0
    down vote

    favorite












    The typical configuration serves two static roots:



    http://www.example.org/static/
    http://www.example.org/media/


    This is STATIC_URL and MEDIA_URL.



    I would like to add a third one to host static files build with Sphinx:



    http://www.example.org/docs/


    I know I could configure this on the level of the web server. Is it also possible to configure this on the level of Django?



    Here is my python package, that implements Sphinx with Django templates and renders it to static pages. A kind lightweight read-the-docs. Still in an early state, yet working.



    https://github.com/elmar-hinz/Django.SphinxCMS










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      The typical configuration serves two static roots:



      http://www.example.org/static/
      http://www.example.org/media/


      This is STATIC_URL and MEDIA_URL.



      I would like to add a third one to host static files build with Sphinx:



      http://www.example.org/docs/


      I know I could configure this on the level of the web server. Is it also possible to configure this on the level of Django?



      Here is my python package, that implements Sphinx with Django templates and renders it to static pages. A kind lightweight read-the-docs. Still in an early state, yet working.



      https://github.com/elmar-hinz/Django.SphinxCMS










      share|improve this question















      The typical configuration serves two static roots:



      http://www.example.org/static/
      http://www.example.org/media/


      This is STATIC_URL and MEDIA_URL.



      I would like to add a third one to host static files build with Sphinx:



      http://www.example.org/docs/


      I know I could configure this on the level of the web server. Is it also possible to configure this on the level of Django?



      Here is my python package, that implements Sphinx with Django templates and renders it to static pages. A kind lightweight read-the-docs. Still in an early state, yet working.



      https://github.com/elmar-hinz/Django.SphinxCMS







      django python-sphinx






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 6:51









      mzjn

      31k566152




      31k566152










      asked Nov 11 at 17:04









      Blcknx

      770119




      770119






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          How about building a url just like you do for the static files? The DOCS_ROOT setting should be a string in your settings.



          from django.urls import re_path 
          from django.views.static import serve
          from django.conf import settings

          urlpatterns += [
          re_path(r'^docs/(?P<path>.*)', serve, 'document_root': settings.DOCS_ROOT)
          ]





          share|improve this answer




















          • Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
            – Blcknx
            Nov 11 at 18:48










          • Glad I was able to help you!
            – nik_m
            Nov 11 at 19:30










          • Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
            – Blcknx
            Nov 13 at 11:56










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251094%2fhow-to-serve-another-static-root-in-django-for-html-pages%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          How about building a url just like you do for the static files? The DOCS_ROOT setting should be a string in your settings.



          from django.urls import re_path 
          from django.views.static import serve
          from django.conf import settings

          urlpatterns += [
          re_path(r'^docs/(?P<path>.*)', serve, 'document_root': settings.DOCS_ROOT)
          ]





          share|improve this answer




















          • Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
            – Blcknx
            Nov 11 at 18:48










          • Glad I was able to help you!
            – nik_m
            Nov 11 at 19:30










          • Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
            – Blcknx
            Nov 13 at 11:56














          up vote
          0
          down vote



          accepted










          How about building a url just like you do for the static files? The DOCS_ROOT setting should be a string in your settings.



          from django.urls import re_path 
          from django.views.static import serve
          from django.conf import settings

          urlpatterns += [
          re_path(r'^docs/(?P<path>.*)', serve, 'document_root': settings.DOCS_ROOT)
          ]





          share|improve this answer




















          • Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
            – Blcknx
            Nov 11 at 18:48










          • Glad I was able to help you!
            – nik_m
            Nov 11 at 19:30










          • Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
            – Blcknx
            Nov 13 at 11:56












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          How about building a url just like you do for the static files? The DOCS_ROOT setting should be a string in your settings.



          from django.urls import re_path 
          from django.views.static import serve
          from django.conf import settings

          urlpatterns += [
          re_path(r'^docs/(?P<path>.*)', serve, 'document_root': settings.DOCS_ROOT)
          ]





          share|improve this answer












          How about building a url just like you do for the static files? The DOCS_ROOT setting should be a string in your settings.



          from django.urls import re_path 
          from django.views.static import serve
          from django.conf import settings

          urlpatterns += [
          re_path(r'^docs/(?P<path>.*)', serve, 'document_root': settings.DOCS_ROOT)
          ]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 18:23









          nik_m

          7,74022139




          7,74022139











          • Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
            – Blcknx
            Nov 11 at 18:48










          • Glad I was able to help you!
            – nik_m
            Nov 11 at 19:30










          • Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
            – Blcknx
            Nov 13 at 11:56
















          • Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
            – Blcknx
            Nov 11 at 18:48










          • Glad I was able to help you!
            – nik_m
            Nov 11 at 19:30










          • Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
            – Blcknx
            Nov 13 at 11:56















          Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
          – Blcknx
          Nov 11 at 18:48




          Thanks, great! It's working out of the box. I edited your answer to also serve in development mode.
          – Blcknx
          Nov 11 at 18:48












          Glad I was able to help you!
          – nik_m
          Nov 11 at 19:30




          Glad I was able to help you!
          – nik_m
          Nov 11 at 19:30












          Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
          – Blcknx
          Nov 13 at 11:56




          Sorry, my edit was rejected by two of three, with the remark I should put that into a comment. I can't put code into a comment.
          – Blcknx
          Nov 13 at 11:56

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251094%2fhow-to-serve-another-static-root-in-django-for-html-pages%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線