Serving static files from root of Django development server

angularjs, django, python

Solution

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` ?

in `urls.py` URLs don't start with a slash; compare `url(r'beer')` with `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:

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

Problem

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. I assumed it would be as easy as adding the following to my urls.py file. ``` 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. With /project/site/app being the directory with the Angularjs files. However, both of these leave me with 404 errors. I'm open to changing the structure of the project if a more obvious solution exists.

Original source

Related problems