Apache with mod_wsgi with Django to develope - django

I have installed Django, Apache2 and even mod_wsgi. With a project, I have Django serving it. When i press the "http://localhost:8000" (which is django server) I have made sure that my websites main page or home page is shown.
The doubt i carry is, when i can do all this localhost:8000 and get the webpage, where does apache and mod_wsgi come into picture? I mean, why should i consider my files to be served by Apache2 when i have Django server? I just searched and came across facts that we have these facilities of apache+mod_wsgi to help us serve the site. But again, i m in confusion as in where is it used to serve my files when i have my website running on Django server?
Please if anyone can make me understand !!
Thank you

Short answer: The Django development server is a piece of poo.
Longer answer: The Django development server is a single-threaded, single-processed server that is little more than a threadbare WSGI server on a skeleton of hopes and wishes.

I used FastCGI.
As I have installed the Django site with FastCGI. I come to conclusion that, Apache has to serve the files, as Django is the development server and by itself can't serve the files online. It requires well known web server like Apache to serve the pages and do the things.
As when the request is sent to the server, the installed apache is used to serve the files and not Django as it has the ability to get the request and then use the files of the project to show online

Related

Is Django Apache or Nginx

I have made a project in the framework Django and I am setting up SSL encryption so it gets https instead of http and removes the safety sign in browsers. In the installation process of Certbot I am asked which software it is running. Django is sadly not an option. I've heard that Django often gets under the category Apache or Nginx, but I am not sure which one my Django project is.
It is an Ubuntu server.
https://certbot.eff.org/
https://letsencrypt.org/getting-started/#with-shell-access
The answer is any of them. I believe you have 2 options, install certbot-django or stop django server and let certbot to create a certificate for you, and then adapt it to django appropriately.
Django is neither.
Apache or Nginx is the web server that will serve your Django application - Django has no bearing or opinion on that.
You just need to figure our which webserver you're using and go from there. If you haven't already set up the webserver then you'll need to pick one and follow a tutorial to set it up.
For example, here's how to set up Nginx with Django. But please do your own research on which one is best for you and your situation. An alternative to both could be Caddy for example.

Host Django site on windows on lan

I have a site that I want to expose to a bunch of colleagues that serves as an interface for some Machine learning tools.
I’ve made the site in Django 2.0 and would like to serve it from a small windows PC under my desk, and then from a more dedicated server once it’s operational.
I’ve had a look around and it looks like my options are using uWSGI or Django it self to serve the site. Obviously Django is mich slower, but on a PC with an i5 i recon it should be able to handle a couple of requests a minute, which is the peak traffic I’m expecting.
FastCGI appears to be depreciated, so what other options, prioritizing ease of confit on my part are there?
So anyone in a similar situation:
I ended up using waitress as the server and whitenoise to serve the static files.
This appears to work sufficiently fast and requires little configuration, once you have have worked out how to get the static files going with whitenoise.
Django itself can serve pages to other machines on your network. SImply start the local server with this command
python manage.py runserver 0.0.0.0:8000
Then, you can access the local website by requesting http://<dev_machine_ip>:8000. Obviously, this is a very simple and inefficient solution if you want to provide this website to many users connected all at the same time. But for tests/demo purpose, it is very handy

Media server vs normal server

I am designing an iphone forum application with django running in amazon ec2. Currently I am learning to deploy django using either nginx or apache. I am confused about media server and normal server. A lot of sources say that nginx is good for serving media files or static content, what does that mean? For normal group conversation/forum application, how does apache and nginx differ in performance etc? When is my mobile application serving dynamic content and when is it serving static content?
Googling will find you better results for a comparison between Apache vs Nginx than anyone on this site can give you. It is too broad of a question and can be highly subjective.
Media Files
Media in a django context generally refers to files that have been uploaded by end users. It is common to have a django view that initially uploads the users file, but then any future access to it is served by a traditional web server like nginx.See the docs for more info.
Static Files
Static in a django context refer to images, javascript and css files. While developing your site, the built-in django development server will serve these files for you. However, when moving to production you will want to use a traditional web server like apache to serve these files. See the docs for more details.
Dynamic Content
This would refer to the content (html, json, xml etc.) that is generated by the views that you write within Django.

django serving media files in production (comparing to PHP frameworks)

I'm a django newbie. I've read that all django projects, deployed in production environment, should serve media files (uploads) through web server such as apache. My question is - why is that?
There are lots of PHP frameworks - eg. symfony 1 and 2 - which don't follow the rule. Once you've made your app accessible through a web server, you don't have to change anything depending on the env you deploy. There is just the DOCUMENT_ROOT configured on the web server and somewhere inside this directory lies the upload directory - that's all. You can be sure that no one will access PHP, sql files and so on - thanks to the proper framework architecture and the document root. Why is it different in django?
edit: besides, preparing different code for different environments (e.g. this) is quite a bad approach, since you can't use exactly the same code to deploy a project in different envs (and the code from the link makes sense only for debug env.
Because with PHP your code is served from web server's public directories together with static and media files. So when you request any of these static files web server serves them directly without executing any PHP code along the way.
In Django your code is running separately and all requests are processed by python code in Django. This is inefficient to serve static files, it's more efficient to serve allow a web server like Apache or Nginx to serve them directly without going through any python code.

How to deploy a WordPress site and Django site on the same domain?

I'm a complete newbie when it comes to sysadmin/deployment. Here's what I'm hoping to accomplish:
Have domain.com be a normal WordPress site.
Have either domain.com/app or app.domain.com be a Django webapp.
Hosting on Linode.
Quick and easy updates of the Django webapp code.
From what I can tell, gunicorn is an elegant way to serve the Django webapp, while WordPress fits most naturally with Apache. Meanwhile, nginx is recommended as a proxy in front of gunicorn and also seems to be used to improve performance of WordPress sites.
So what I'm thinking is: use nginx as a proxy server that routes all incoming web requests to either gunicorn (for the Django wepapp) or Apache (for the WordPress site). The Linode host would be running nginx, gunicorn, and Apache simultaneously.
Meanwhile, for updates of the Django webapp, I can simply update to the latest version of the code via github.
Does all that make sense? Am I even understanding things conceptually correctly? Or barking up the wrong tree entirely? (For instance can/should I just use a single Apache server to route requests to either WordPress or the Django app based on URL?) What gotchas and issues should I keep in mind as I research how to get this running nice and smoothly?
UPDATE: I've side-stepped all of this by (1) using Heroku to host my Django app, (2) using a CNAME record to map app.domain.com to the Heroku-hosted Django app, and (3) leaving (for now) the WordPress site on its existing host at domain.com. Thankfully, after gaining great new respect for what sysadmins and db admins do as I investigated all this, now I can get back to coding!
#Ghopper21
+1 for your question first.
Now, This is really interesting to know how it's possible in real time execution. I checked with some of my geek friends and I found tremendous response, here are some of suggestion with reference I got after brainstorming with them.
First of all check this link for deploying & running WP altogether with Django on Nginx +uWSGI...
These two threads of support forums from Webfaction.com gives you more idea about how they are recommending it to their client...
Deploying Django and Wordpress in same domain
wordpress + django on same account - advisable or not?
Hey, I got one support ref. of Stack Overflow itself, which is explaining how to achieve it on APACHE server...
How do I run Django and PHP together on one Apache server?
And last but not least, the one where a geek like us integrated WP with Django...
Integrate WordPress and Django