This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 5 years ago.
I am getting into Flask/Python model and it seems to be getting along fine in the initial stages. Is there a way to run python application as a web application on a simple desktop computer and use that app over LAN? If yes, what will be the process for that?
I mean, I understand that frameworks like flask/django/bottle run their own server instance which results in the execution of such web apps. In this way they are practically acting as IIS/Apache. Correct?
The reason for this question is that this app will be accessed by only 4-5 individuals & we all are a part of the same team.
If the number of users are going to be limited to 4-5, then django server might just be enough for you. You'll just need a router and devices with WiFi access or just an access to the router.
You can simply run your server as,
python3 manage.py runserver 0.0.0.0:8000
python or python3, depending on what you're using.
After this your django project would be visible on all the devices connected to your router, at the address,
Local-IP-Address-Of-Device-Runing-Django-Project:8000.
Note: Django is excellent during the development phase but it's not recommended for production use, or when users increase. see docs here
So I recommend that if number of users increase(increase in load), ideally you should switch to gunicorn with ngnix or apache server (gunicorn is easy and widely used for python apps. It usually works well ngnix as a reverse proxy; entrance point to your server). There are many tutorials for hosting your website using gunicorn with ngnix as a reverse proxy.
Hope this helps. Thanks.
Related
This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 1 year ago.
I have a flask web application build as an internal tool in our org.
now it is decided to move it to production ( on AWS ).
i can't find anything useful other than it says that Flask is not recommended for production.
Is there still some way to build setup of the flask app as the main web server?
The message you are quoting about Flask not being ready for production only refers to the builtin development server.
You should use a WSGI server such as Gunicorn in combination with Flask.
Also, I usually put NGINX in front of them to handle SSL/TLS, or even Haproxy, depending in the expected load/availability.
Flask is well equipped to handle requests but yes it has it's own development environment which isn't recommended to use in production, you have to use proxy servers like uwsgi, gunicorn that replaces your development server.
Now you can also not handle request from uwsgi servers, you want a proper heavy duty reverse proxy server like NGINX or Apache2 to do that work for you.This might resemble the logical flow.
You can refer to below articles they explain such details clearly and with procedure.
Reference: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04
This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 2 years ago.
So I'm aware flask's development server isn't advised for production for a few reason (see this question's top answer). However these issues seem to imply either a problem with scalability or security. I have a question related to this (that may be completely naïve) - give the following setup is there any issue using flask:
The webserver itself doesn't run the flask apps, they are stored on a Kubernetes machine that is linked locally.
The processes are demanding enough that running more than one concurrently would cause slowdowns, and thus load balancing between Kubernetes is already planned.
The user should never be able to directly access the flask apps since they only respond to local addresses (assuming my understanding of how flask set up works).
To my eye this seems to bypass all of the reasons that flask shouldn't be used for deployment - but I still feel like I'm doing something wrong if I go ahead with the above plan. It wasn't designed this way to deal with flask, it just happened to solve all the issues I've read about flask - is there any further dangers than direct user access and scalability and parallelism?
One of the problem I can see a bit above the one you mentionned is software architecture.
When you design a component/software with Flask you should plan for a webserver, may it be gunicorn, uwsgi, cheroot, etc.
It is not really hard to make one of thoses solution works, and you'll be ready for production and it's easy to change once you have written things to use one. I personnally test locally with cheroot and deploy with gunicorn on cloud platforms.
This question already has an answer here:
Django server killed frequently
(1 answer)
Closed 5 years ago.
I am trying to host my personal website, I am new to hosting websites business, so this may be a Noob question.
So I made my website using django, and tested everything locally. Now I want to make the site public, then I came across this :
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment
which seemed to be a pain in the arse.
But, Then I figured i could make the website available on all interfaces using:
python manage.py runserver 0.0.0.0:80
Now I can access the website using http://myIp/myapp
So my question is, "Is it a good idea to host websites using the django dev server"
The gut feeling is a "No", but I really want to know "Why?"
Your gut feeling is right. You better use a WSGI server that is going to serve your django app.
It is not that hard to configure.
Personally I like to use Gunicorn, which is easy to set up. Setting it up may look something like this:
gunicorn mirador_django.wsgi:application \
--bind 0.0.0.0:8000 \
--workers 4
(see : http://docs.gunicorn.org/en/latest/run.html)
I then set a reverse proxy on my web server to point on the Gunicorn. For Nginx the info are on the gunicorn website: http://gunicorn.org/#deployment
You can also easily set it up on an apache server as I am currently doing.
Hope it can help.
You can use Apache,it's easy, and there are plenty of startup guides with django and apache, even in the django docs.
What I want to know are actually 2 things.
Part 1:
I have a developed source code for an application in python that uses Django framework.
What I want is to be able to run the code on a developer machine and see the result. What do I need for it?
(my guesses):
Python development enironment (Eclipse/PyDev/Aptana Studio 3 seem to be the better ones for windows not sure linux yet),
I also have a postgre database already setup (I know there's a file where I have to specify connection information)
- something installed from django or would this be already included in the code that I have?
Part II:
I also want to make a dev server accessible through internet.
- this is the major part of the question and the most important. How do I publish the app?
- I have a linux machine that I would do this on, but unsure of all the things I need. Apache server?
To answer your questions:
What you need: A list of requirements and instructions to get started with Django is available here: http://djangobook.com/en/2.0/chapter02/.
Database: that chapter also includes a section on configuring access to your database, with a specific section on postgreSQL.
Dev server: To start a basic development server, see this tutorial section
Deploying django (production): For instructions on how to deploy Django for production, see chapter on deploying Django.
Publishing on internet: as for making your dev server accessible through the internet, ask on https://serverfault.com/. Make sure you provide more information about your network setup, what you've tried, what isn't working, etc. (Briefly, you need to make sure that the host you are running your server on is on a publicly accessible IP, or has port 80 forwarded to it from such a host. If in doubt, speak to your sys/network admin if you have one. Or use a django hosting service such as those listed on http://djangohosting.com)
IDE : Regarding IDE, it's down to personal preference. What you mentioned are fine and can run on Linux too.
As a first step, I suggest you follow the tutorial which guides you through the process of starting a development server and developing a basic app.
Even if your goal is to deploy an existing app, the tutorial will give you an idea of how the different components work together (apps, models, urls, templates, etc) which will help with debugging when something goes wrong with your deployment.
Good luck.
You need Python, Django, a WSGI container (e.g. mod_wsgi, uWSGI, Paste Deploy), and a database server. You make the Django project available as a WSGI app, bound to the appropriate interface on the machine.
I'm learning Django and working on sample sites.. I registered at alwaysdata but am unable to view the site after I go 'manage.py runserver' in the SSH (this is after I've created the project and navigated to the appropriate directory, of course).
I appreciate any help.
Thanks
Have you taken a look at the wiki entry regarding the django dev server? Google translate seems to indicate that you need to request some ports open first, and that once you've got them assigned you can pass in one of those port numbers to runserver to run it on that port.
If you need the translated-to-English version, here's a link
I am also an alwaysdata customer. Daniel DiPaolo gave you the right links to get it working on ssh with the dev server. The google translation seems correct to me. You need to request a port range in order to use the dev server on ssh.
But this is intended only for debugging purpose and should run for a short while.
Here is how to deploy with fastCGI which is the regular way to deploy a Django site on alwaysdata.
http://wiki.alwaysdata.com/wiki/D%C3%A9ployer_une_application_Django.
Google give a decent translation
AlwaysData is running a forum at http://forum.alwaysdata.com/ mostly in French but questions in English are welcomed.
The devserver included with django is for testing purposes, only on your local machine and should not be used on a web host. From the docs:
DO NOT USE THIS SERVER IN A PRODUCTION
SETTING. It has not gone through
security audits or performance tests.
(And that's how it's gonna stay. We're
in the business of making Web
frameworks, not Web servers, so
improving this server to be able to
handle a production environment is
outside the scope of Django.)
If i have somehow misinterpreted your question, i apologise.
When you enter manage.py runserver you're running the development web server on the loopback interface (127.0.0.1). You could test this out by running wget 127.0.0.1 on the same server that the development web server is running.
If you want it to be on the internet so you could access it from outside that server, you'd have to specify your public ip. For example, to run the web development server on ip 1.1.1.1 and port 8080 (personally recommend using a non-standard port):
manage.py runserver 1.1.1.1:8080
To find out your public ip, try running ifconfig on SSH.
Also, you might have to check out the firewall settings with your ISP/server provider.