Tchec
Tchec

Reputation: 97

Different hosting site for serving static content using Django?

I am all new to this web thing and learning Django framework. What I needed to know was, can i serve my both apps and static files to different hosting sites? I hope i have made my question clear, if not please ask.

Upvotes: 1

Views: 457

Answers (3)

fideloper
fideloper

Reputation: 12293

If i'm reading you correctly, I think you're asking about best practices on serving static files separately from your Django app.

Best practices, in my mind, would be to server DJango behind a proxy such as Nginx. This would let Nginx server static files, and pass application requests to DJango. Your Django app can be run as a fcgi process.

Here are some docs on that topic:

  1. Nginx + Django with fcgi.
  2. Nginx + Django with uWSGI
  3. SO question/answer on Nginx + Django with uWSGI

Hope that helps rather than confuses.

Upvotes: 1

Marcin
Marcin

Reputation: 49856

Technically, yes. However (a) this will likely make your site much slower (b) many browsers will refuse to load resources from a different host than that serving the html, due to implementing CORS (see: https://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing). You'll need to enable appropriate headers and options on the static server to make it work.

The normal thing is to serve all of your content from the same hosting service, except in so far as you use a CDN.

Upvotes: -2

Derek Peterson
Derek Peterson

Reputation: 603

Yes, absolutely. You can find more information in the Django docs for "Managing static files" and "Deploying static files". It just takes a little configuration of your settings.py file.

Upvotes: 2

Related Questions