Django Deployment on windows - django

I am learning python and Django now. I have a question related to deploying Django project on windows 7. I know how to start the test server in django and see the project. But I have to do start the server manually every time I restart the PC. Also I have to keep the terminal window open.
Consider the below scenario for php projects.
We copy and paste the php files in htdocs or www folder in apache server and access them using the respected url. Web Server is running in the background. We dont have to start the server on windows restart.
Is something similar possible with Django on apache or any other server?
If yes, how should I go about it?
Thanks in advance.

For anyone stumbling around for an answer to a similar problem with deploying Django on a Windows server, here is a guide
Deploy Django with Apache and mod_wsgi on Windows Server 2019
To have Apache24 service automatically run on startup, make the changes in Windows Services dialog.

Related

Attaching oTree(Django) to IIS with Windows VM using Hypercorn or equivalent?

I have been looking into adding oTree to a website hosted in Windows 2012 IIS on a Windows 10 VM.
To run locally I just run otree prodserver inside the directory of the apps folder.
The app runs on localhost:8000 unless specified otherwise, which allows me to generate unique urls for players on the local network.
When looking at attaching to the IIS so it can get ran using a URL on the cloud remotely, not sure how to go about it.
With Django attaching the wsgi and enabling it to the IIS. Inside oTree no file exist. It seems to use Uvicorn and Scarlett to run asynchronously with ASGI server.
From what I can tell it would be easiest to use Hypercorn and run it with a web.config file. But that's where I am lost.
I'm not sure where the ASGI module/app is to execute with Hypercorn.
Can I just run a CLI with otree prodserver and attach that to Hypercorn to host the localhost:8000 on the IIS with a proxy?

How to set virtualenv to stay active on a host server

I created a website that uses vuejs as the frontend and django as the backend with another service running behind everything that im making api calls to.
So django is setup in a way to look at the dist folder of Vuejs and serve it if you run manage.py runserver. but the problem is that my service that I created is
is also in python and it needs to run in a virtualenv in order to work (It uses tensorflow 1.15.2 and this can only run in a contained environment)
I'm sitting here and wondering how I can deploy the django application and keep the virtualenv active and Im coming up with nothing, I've tried doing some research on this but everything I found was not relevant to my problem. I've deployed it and when I close the ssh connection the virtualenv stops.
If there is anyone that can enlighten my ways I would appreciate it.
i think you need to nginx: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
if you are search for keep states just in terminal i suggest tmux https://github.com/tmux/tmux/wiki
You can use uWSGI and nginx to deploy Django apps on server. Here's helpful articles:
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
Django official docs also has a page about it: https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/uwsgi/
There are articles from developers so you can refer them in case you get stuck anywhere:
https://www.freecodecamp.org/news/django-uwsgi-nginx-postgresql-setup-on-aws-ec2-ubuntu16-04-with-python-3-6-6c58698ae9d3/
https://medium.com/#biswashirok/deploying-django-python-3-6-to-digital-ocean-with-uwsgi-nginx-ubuntu-18-04-3f8c2731ade1

How could i use let's encrypt behind a django application without stopping the server?

I have a django application running on a server. I want to use let's encrypt to provide an encrypted connection. I could use the standalone option of their ACME client, but i don't want to stop my server, what i would have to do.
So there is the webroot option, that work with my allready running webserver (nginx). Django would process the request in this case. My question is, how should it look like on the django side to get this running (keeping automated renewal several months in mind)?
I don't know what setup others use, but I generally set up Django apps with Nginx serving static content and Gunicorn as the application server. It's widely accepted that Django apps usually use this kind of two web server setup. The standard instructions for setting up Let's Encrypt with Nginx worked fine for me.
Or Digital Ocean have an excellent guide too.
EDIT: It looks like Nginx can do a "graceful" reload that just updates the config with no downtime. For Debian or Ubuntu pre Systemd this would be sudo service nginx reload, while for a distro with Systemd the command is sudo systemctl reload nginx.service.
In case other users come this way like I did from Google, here's how I improved this situation:
I was unsatisfied by my options when it came to creating ACME challenges for Let's Encrypt when running a Django application. So, I rolled my own solution and created a Django app! Basically, you can manage your ACME challenges as just another object, and the app will produce the proper end-point URL.
Yes you are installing an app which means a deploy / update to your app, but once you've done that managing your challenges is far easier in the long run.
Simply pip install django-letsencrypt and follow the README to be on your way.

bitnami django, solution to restarting service?

Hey I use installed bitnami django 1.3.0,
but whenever I add changes to urls.py or views.py in my system due to some error. The error won't disappear after refresh.
I have to restart my bitnami Service, "stop" and then "start" it, which is time consuming, I feel like I'm coding C# apps in visual studio. Sometimes even that doesn't work, I have to sometimes restart my computer and then I suddenly realize "oh wow, the error is solved now!"
Any solution to this? Why does everything require a runserver / restart?
You can use Apache for deploy your application in production but use the Django server for development. You will need to configure your application for being served by apache later (modifying the settings.py and the apache configuration file) but during the development you won't need to restart the server for every change.
Everything requires a restart because of the way that the python process operates. It does not reload the file when it's changed (outside of runserver..which is an anomaly, and just there for convenience)
Python execution isn't like PHP execution in that way, and your code isn't dynamically loaded on every page refresh, it's loaded on every server restart.
Hope that helps.

Django: Restarting Shared Server When Changing MVC Python Files

Essentially,
I am doing some of the development for my Django app straight on my shared server rather than on a local machine (I know that initially is the problem) however regardless, I would like to know if there is a way to restart the apache server on my shared hosted server (Bluehost) for when I modify any of the python files.
I'm not sure how the Django framework is setup, maybe restarting the webserver is not needed?
THanks!
How is the apache configured to run python codes? are you using fcgi, wsgi or something else?
What i do is, i use a fcgi process and restart fcgi process without the need to restart the webserver. In my case web server is nginx but it should be same in apache if you are using fcgi.