Missing bootstrap resources in Django-Rest-Framework

后端 未结 3 670
日久生厌
日久生厌 2020-12-17 17:41

I\'m using the new django-rest-framework 2.0 and have been following the tutorial for creating a rest based API. The API is now complete, however I am having trouble getting

3条回答
  •  轮回少年
    2020-12-17 18:17

    CSS is not found. The fix would be to make the missing css files (404 for files seen in the browser console) available. That's it.

    You can make the css files accessible in backend(need some tweaks) or in front end(comparatively easy).

    This solution works perfect if you have a seperate frontend & backend(restful) setup such as Django-Django rest framework and AngularJS..

    Let us say if django backend is running at 8000, and front end is running at 9000.

    • frontend.example.com loads front end JS app running at 9000

    • backend.example.com loads django app running at 8000

    in settings.py

    import os
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    
    STATIC_URL = 'http://frontend.example.com/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    

    then in terminal

    $ python manage.py collectstatic
    

    Then go to dir where you have the folder static

    $ cp -rf static/* /frontend-code-directory/static/
    

    DONE.

    What I have done basically, is copying all css of django apps to the frontend. Frontend serves this easy as frontend is already a collection of static files.

提交回复
热议问题