How to deploy Django code without restarting web server [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I decided to move from PHP and start using Django. I have successfully installed Python and Django on my web server. How can I just code my Python/Django program, throw it to the server over FTP, and run it without the need to SSH to the server and restart the django server every time?
What is the method to run Django codes exactly the same way we run PHP code (having the server running all the time if possible)?
My server runs CentOS 5.8 and Apache.
Edit:
Alright I really recommend this tutorial for who ever want to setup dJango on a web server , my recommendation after reading a lot of posts. Using dJango on Nginx web server is the most powerful performance you could get
https://code.djangoproject.com/wiki/DjangoAndNginx

You can't magically make Django run like PHP. Please look at the deployment documentation, as it's some of the best around.
You'll see step by step instructions for apache.
As for not having to SSH every time you load new code, the best tool for this job is fabric.
http://docs.fabfile.org/en/1.5/
Fabric is an amazing tool that is extremely easy to install and configure, which lets you run commands on your remote machine from your local machine.
For example, I simply type fab production deploy on my local machine to...
push git changes
pull git changes on remote
run pip install
migrate database
run collectstatic
finally "restart" apache - touching wsgi file.
I just want to stress that fabric is not like those deployment build scripts which are complicated. Fabric will literally take you 10 minutes to set up.

Related

Deploy Django Project Using Pyinstaller [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
Improve this question
I have a django project, that works similar to Jupyter Notebook, in terms of Being a program launched offline in localhost on a web browser, moreover my webapp has an opencv webcam pop-up, that will be launched when you press a button.
I want to deploy my django project, so it can be launched by just clicking a file in Windows.
According to what I read, There are two possible solutions:
Install Python Interpreter with Dependencies on client computer first, and using a bat file, to launch the django server.
Containerizing the Django project with Python and its dependencies, either using Docker or perhaps an exe file?
Which solution is better? I would prefer the second one personally, but I’m confused how to do so.
Can it be done as simple as using pyinstaller or not?
Here are my dependencies for reference:
Django
pillow
django-object-actions
django_user_agents
django-cleanup
opencv-python
imutils
cmake
dlib
face-recognition
I think that the best practise would be to use containers like e.g. docker. After that you have the following benefits:
Dependencies inside the container machine (automatically with pip install from requirements file)
Multiplatform possibility
Versioning with tags
You can run database in a second container if needed (combined with docker compose)
Click and run with docker desktop
fyi: There a lots of tutorials on how to deploy django in docker containers :)

how to run django server on background at startup? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I wanna Django runserver on the background when I start my laptop I'm using ubuntu.
I tried using "screen" but this is not what am looking for.
For background runserver on OS startup, you can pick Gunicorn or Supervisord, or Uwsgi as process runner. These folks can run your project in auto mode, and if you make them as ubuntu services, they can boot up and run project after OS startup.
gunicorn
uwsgi
supervisord
Last link combines gunicorn with supervisord: Gunicorn will run project by command, and supervisord will be a process watcher for gunicorn.
Almost all links have receipt for configuring nginx, you may skip this step, because it's used for servers to proxy requests to your app's process. On laptop you may run project on localhost, it's just fine for debug or development.

Python Restful API [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have written a python script that will connect to the oracle database using cx_oracle and gets data and performs some action on it.
I want to expose this python script as a Restful API. In google, I read that using flask we can deploy a Python script as a Web service.
What I am not clear
The flask itself behaves like a server?
Can I deploy the python Webservice in the Web logic server?
I want to deploy this Webservice in production. How can I provide security to this?
In another site, I read using Connection, Swagger we can implement it.
I am actually written using flask, flask-jsonpify, flask-sqlalchemy, flask-restful.
Please suggest which packages i need to use to deploy it as WebService.
Let me know in case of any other details needed. Thanks in advance for your suggestions and guidance.
Vijay
The flask itself behaves like a server?
It can
Can I deploy the python Webservice in the Web logic server?
Not unless you are using Jython as WebLogic runs Java applications
I want to deploy this Webservice in production. How can I provide security to this?
See next point
In another site, I read using Connection, Swagger we can implement it.
See next point
I am actually written using flask, flask-jsonpify, flask-sqlalchemy, flask-restful.
Sounds like you've done some research into what packages you need. Maybe find more to get swagger and security figured out
Please suggest which packages i need to use to deploy it as WebService.
Refer point 1. flask is all you need to run the web server

How to run my Django application automatically on production server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I built an application on my local machine with Python and Django. Its working fine. Now, I would like to automate the process to start my Django application on a production server.
What I have to do to achieve that?
Django documentation don't recommend to use Django built-in server on production.
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.)
It's recommended to use gunicorn or uWSGI to launch your WSGI application :
- How to use Django with gunicorn
- How to use Django with uWSGI
Another good practice, it's to use supervisord to start your process, Then if it dies or get killed for some reason, supervisord will restart this process.
And to finish, use nginx or apache as proxy server, which are strong server that can handle the charge. Most of tutorials or documentations, recommend to use nginx because it's a high-performance HTTP server.
NGINX is a free, open-source, high-performance HTTP server and reverse
proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its
high performance, stability, rich feature set, simple configuration,
and low resource consumption.
Check this to know how to configure them :
- Deploying Gunicorn with nginx
- Deploying uWSGI with nginx
Also before deploy your Django app, read this checklist, to make sure everything is well configured : Django - Deployment checklist
With this architecture and tools, you will be able to launch your gunicorn process with a simple supervisord command. That's all. Then gunicorn will launch your WSGI application.

How to implement auto-update functionality for web application on multiple server? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need an idea how to implement following
1. Want to build python application which will update itself when the new patch is available
2. It will run the unit test to check if the patch deployed successfully
3. If there are any failure during installation it will rollback automatically
What I don't know
A. Not sure how to build a patch from the source code
B. Algorithm / standard process to check about the new updates are available
C. Auto deployment/Rollback process
Any suggestions/ links?
I implementeed a server that recognizes the changed source code and pulls the new code. It is hosted at pythonanywhere.com at this url and the code is on github. This answer bases on my experiences when implementing the update functionality.
When you version your code with git you usually
have a master or deploy branch that works
have a develop branch that is merged into the master-->deploy branch when all the tests run through.
This way you only need to know when the deploy branch changes in order to figure out when to restart. Tests should be run before in order to have no downtime. If you run the tests on the deploy system it may take them too much time or the invalid code destroys the system.
So the deploy branch works because it was tested before.
For automated testing you can use a continous integration server like travis that downloads the code and tests it. It can be asked about whether the test run of a specific commit.
When you host your code on github then you can specify a push http address. I used http://server/update Whenever the repository is changed github notifies your server then.
You can then update the source code by pulling it from git and if the deploy branch really changed then you can restart the application. I can not do this in the server ut maybe you can.
Scenario:
I push code to github
github sends a POST to http://server/update
#post('/update') # bottle code
def pull_own_source_code_and_restart():
with inDirectory(server_repository):
previous_commit = last_commit()
text = git.pull()
current_commit = last_commit()
if previous_commit != current_commit:
restart()
return "Git says: {}".format(text)
have a look at these two files:
command_line.py for the git commands
bottle_app.py for a derivating implementation if the server can not restart itself.
A version control system usually does the 'patching' for every version. I use git. If git is unknown to you now, learn it! Here is workshop material for Pythons Django and git: http://www.opentechschool.org/material.html
Let me now if this information is sufficient to implement such a functionality in Django. Please post your code here when you got it to work.

Categories

Resources