Django-Rest-Framework中缺少引导资源 [英] Missing bootstrap resources in Django-Rest-Framework

查看:150
本文介绍了Django-Rest-Framework中缺少引导资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的 django-rest-framework 2.0 ,并且一直在遵循用于创建基于休息的API的教程。 API现在已经完成了,但是我无法获取加载的引导资源,所有这些都从Django返回404找不到。

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 the bootstrap resources to load, all return with a 404 Not Found from Django.

我觉得资源应该是从django-rest-framework模块的静态目录中加载,当我在python2.7 / dist-packages / rest_framework / static / rest_framework上做一个列表时,我看到了我需要的css,js和img目录,无法在文档中找到显示如何将CSS从模块链接到我的项目的任何地方。

I feel like the resources should be loaded from django-rest-framework module's static directory, And when I do a listing on 'python2.7/dist-packages/rest_framework/static/rest_framework' I see the css, js, and img directories I need with but I have been unable to find any place in the documentation that shows how to link the CSS from the module to my project.

这里的最佳操作是什么?我应该下载源码并将文件夹复制到我的/静态目录中吗?因为我需要检查这个项目到一个中央的repo中,这个问题是不合适的。想法?

What is the best course of action here? Should I download the source and copy the folder into my /static directory? Symlinking is out of the question because I need to check the project into a central repo.. Ideas?

推荐答案

假设您的意思是无法为可浏览的API加载引导静态资源? (虽然我想这可能是您试图在项目的其他地方使用它们)?

First up, I'm assuming that you mean the bootstrap static resources aren't loading for the browsable API? (Although I guess it could be that you're trying to use them elsewhere in your project?)

如果您正在运行 DEBUG = True 它们应该自动投放,但一旦运行 DEBUG = False ,您需要确保运行 manage.py collectstatic ,并确保您的 STATIC_ROOT STATIC_URL 设置正确。

If you're running with DEBUG=True they should be served automatically, but once you're running with DEBUG=False you need to make sure to run manage.py collectstatic and ensure your STATIC_ROOT and STATIC_URL settings are correct.

Django的静态文件文档应该有助于: https://docs.djangoproject.com/en/dev/howto/static-files/

Django's static files documentation should help: https://docs.djangoproject.com/en/dev/howto/static-files/

如果你还没有运气我建议您仔细检查您的Django版本(支持1.3及更高版本)以及REST框架版本(从第2版起的任何内容),并确保逐步完成教程,特别注意项目设置。

If you're still not having any luck I'd suggest you double check your Django version (1.3 and upwards is supported), and REST framework version (Anything from version 2 onwards), and make sure you step through the tutorial step-by-step, taking care particularly with the project setup.

这篇关于Django-Rest-Framework中缺少引导资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆