My goal is to have an Angular project being served from the root of my development server. The files will be completely static as far as Django is concerned, no Django template processing is needed. The angular project will then make resource calls to a Django project located at /api/ on the same development server, which will then return json results generated from a view for the Angular project to process.

我的目标是从我的开发服务器的根目录中提供Angular项目。就Django而言,文件将是完全静态的,不需要Django模板处理。然后,角度项目将对位于同一开发服务器上的/ api /的Django项目进行资源调用,然后将返回从Angular项目的视图生成的json结果进行处理。

I assumed it would be as easy as adding the following to my urls.py file.

我认为这就像在urls.py文件中添加以下内容一样简单。

url(r'^/', 'django.views.static.serve', {
        'document_root':'/Users/kyle/Development/project/site/app',
}),

Or

+ static("^/$", document_root="/Users/kyle/Development/project/site/app")

To the end of the urlpatterns.

到urlpatterns的结尾。

With /project/site/app being the directory with the Angularjs files.

/ project / site / app是Angularjs文件的目录。

However, both of these leave me with 404 errors.

但是,这两个都让我有404错误。

I'm open to changing the structure of the project if a more obvious solution exists.

如果存在更明显的解决方案,我愿意改变项目的结构。

3 个解决方案

#1


1

  1. note that by default Django won't serve a directory listing. Do you still get a 404 if file /Users/kyle/Development/project/site/app/beer.jpg doesn't appear as http://localhost/beer.jpg ?

    请注意,默认情况下,Django不会提供目录列表。如果文件/Users/kyle/Development/project/site/app/beer.jpg没有显示为http://localhost/beer.jpg,你还得到404吗?

  2. in urls.py URLs don't start with a slash; compare url(r'beer') with url(r'^/beer')

    在urls.py中,URL不以斜杠开头;将url(r'beer')与url(r'^ / beer')进行比较

I suggest just going for the standard STATIC support. It's awkward, but lets you serve file simply during development, and switch to a 3rd party server (ie Nginx) for production:

我建议你去寻找标准的STATIC支持。这很尴尬,但是让你在开发过程中简单地提供文件,并切换到第三方服务器(即Nginx)进行生产:

https://docs.djangoproject.com/en/dev/howto/static-files/

更多相关文章

  1. 为独立的“产品”打包django项目及其依赖项
  2. Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标
  3. 如何使用os.listdir()忽略隐藏文件?
  4. 用python解析word文件(二):table
  5. python cookboo 文件与IO 函数
  6. 解决Linux下运行Python脚本显示“: 没有那个文件或目录”的问题
  7. eclipse中写python文件找不到
  8. 用于Python项目的低内存和最快查询数据库
  9. Python 文件的基本操作

随机推荐

  1. 系出名门Android(4) - 活动(Activity),
  2. listview常用的优化技巧
  3. Android序列化
  4. android开发步骤简要笔记
  5. 同步、更新、下载Android Source & SDK f
  6. Android的核心服务 2
  7. Eclipse Android project name有错误, sou
  8. android 检测网络或wifi是否开启
  9. GridView的简单使用,带有点击事件
  10. [入门]Android的应用程序框架