Background
I have a free account at pythonanywhere.com. My thanks to them for providing this very nice free service and learning experience.
To the PythonAnywhere folks who encourage me to use StackOverflow for questions about their site, I'll first say that I really like what you all have done with that site, and I'm excited to start building something there myself.
I've already done the first tutorial within pythonanywhere.com with Flask and a second simple webapp (that I adapted from your first tutorial) exactly the same but using your built-in django 2.2 in place of Flask.
Now I'm trying a tutorial from another site using python 3.8 and django 3.1.
I'm following along in Chapter 2 of the djangoforbeginners.com site (helloworld app) and trying to implement instructions there in my pythonanywhere.com account. I know I need to adapt some of the djangoforbeginners.com instructions to fit the pythonanywhere.com environment (e.g. pipenv didn't work, but pip install django~=3.1.0 did work).
(This is not my main question, but an example of the problems I expect to encounter adapting a tutorial from another site to the pythonanywhere.com environment) I encountered a problem with the python manage.py runserver step:
When I run the code above, I see the following error at the bash console:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 13, 2020 - 20:33:32
Django version 3.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Error: That port is already in use.
And that makes sense to me because when I try to visit my webapp at username.pythonanywhere.com, I see a "Coming soon" page (after disabling my webapp in the dashboard; with my webapp enabled in the dashboard Web tab, I see a default "Hello World" page) which I know in both cases means that port is indeed already in use (by the server provided by pythonanywhere.com). So thinking about it a bit after seeing that error, I now think I should not even have attempted this python manage.py runserver step in the pythonanywhere.com environment. Duh! ;)
So moving on to my real question:
I've already followed instructions I found at https://help.pythonanywhere.com/pages/Virtualenvs including the part at the end where it reads: "Now that you have a virtualenv, and you know its path, you can go and enter it back in the Web tab.
Go to the Virtualenv section, and enter the path: /home/myusername/.virtualenvs/myvirtualenv"
I created my virtual environment using mkvirtualenv virtualenv01py38 --python=/usr/bin/python3.8 in pythonanywhere.com's bash console.
I also added to the Web tab in pythonanywhere.com's dashboard my source code directory for this web app: /home/username/projects/djangoforbeginners.com/ch02helloworld
When I used the dashboard Web tab to reload the web app, I saw this error message: "Your webapp took a long time to reload. It probably reloaded, but we were unable to check it."
But instead of the familiar Django welcome page, when I visit my webapp's URL, I see an apparently static html page:
"Hello, World!
This is the default welcome page for a PythonAnywhere hosted web application..."
So my question in general is how to implement the helloworld app from djangoforbeginners.com within the pythonanywhere.com environment?
And more specifically for now, my question is why I'm not seeing the familiar Django welcome page shown at djangoforbeginners.com in the first image, and how to continue to move forward past the python manage.py runserver step when I am apparently seeing pythonanywhere.com serve up its default hello world webapp (apparently just a static html page) instead of the django 3.1 hello world app that I'm trying to get it to serve up from the djangoforbeginners.com tutorial?
Thanks in advance for any suggestions.
You cannot run your Django web site from a console. You will need to use a web app if you'd like it to be available. We have a help page that describes in detail how to run an existing Django project as a web app.
Like Glenn said you would have to create a Web App under the Web tab first. I wrote an article How to deploy Django to Pythonanywhere that walks you through the whole process from GitHub, HTTPS, MySQL, and Environment Variable.
Related
I have a Python application that's that has been working correctly as backend for my website, up to now I have been running it using "python manage.py runserver IP:8000" in CMD. However I would like it to start using HTTPS, but when I try to access through my browser on https://IP:PORT I get the following error:
You're accessing the development server over HTTPS, but it only
supports HTTP.
The server I am running all of this is a Windows Center 2019 DataCenter, normally on a linux environment I would just use NGINX+GUNICORN.
I was browsing possible solutions and stumbled upon this, however I already am using IIS to host a website (My frontend), so I needed to figure out how to host several websites for the same IP, I have now found this.
Long story short, I configured the new IIS website for it to access my django, I then changed the hostname since both frontend and the new backend will using the same ip and ports (80, 443).
But now I have hit a spot where I'm confused due to my lack of experience in IIS and networking. I can't seem to understand how the request will go through to my Python-Django APP.
Something important to mention on how I access the Django APP in the past.
Lets say my front end is https://pr.app.com, whenever any request needed to be made to the backend. I would ask for said information in http://pr.app.com:8000/APIService/..../
This is how the binding for my frontend looks like
And this is the binding for the new backend where I changed the hostname as the second guide linked said
Any guidance or help would be most appreciated,
Thanks in advance
*Update
So I tried pausing my frontend website and used these bindings on the new backend website, I was able to get a screen of Django meaning it seems to be working or at least communicating.
Now I would need to have the hostname of the backend (pr.abcapi.com) somehow refer or redirect to the hostname of the frontend (pr.abc.com).
How could I achieve this?
In my droplet is running several PHP websites, recently I tried to deploy a Django website that I build. But it's doesn't work properly.
I will explain the step that I did.
1, Pointed a Domain name to my droplet.
2, Added Domain name using Plesk Add Domain Option.
3, Uploaded the Django files to httpdocs by Plesk file manager.
4, Connected the server through ssh and type python manage.py runserver
0:8000
5, My Django Website is successfully running.
Here are the real issues occurs, We need to type exact port number to view the website every time. Eg:- **xyz.com:8000 **
As well as the Django webserver is down after sometimes.
I am newbie to Django all I have experience in deploying a PHP website. If my procedure is wrong please guide me to correct procedure.
Thanks in Advance.
Django Runserver is not a production one, it should be used only for development. That's why you need to explicitly type in the port and it sometimes go down because of code reload or other triggers.
Check Gunicorn for example, as a production server for Django applications. (there are other options also)
I suggest following this guide. Covers initial setup of django with gunicorn and nginx which is essential for deployment, you don't have to add the port to access the site. It doesn't cover how to add the domain but it seems you already know how to add the domain though.
I am new to Python deployment. I have a Python Web API made in Flask. Want guidance on how to publish the python code as web API so that Dot Net program can consume it and take benefit of Python / ML.
Apologies for such generic question, but any help or approach or documentations on the same would be grateful.
Thanks In Advance!!!..
As far as I know, if you want to deploy python application to the IIS. I suggest you could follow below steps:
1.Install Python on your server.
2.Install wfastcgi on your server.
3.Install the IIS(contol panel->Programs->Programs and Features->Turn Windows Features on or Off) with the CGI
4.Create a new IIS web app for the paython project folder.
5.Modify the handler mapping to add python handler. Notice: Modify the path based on your python and wfastcgi path
Run your application
More details, you could refer to below article:
https://www.storehubs.com/Blog/deploy-python-flask-application-iis/
https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019
I am beginning to learn web development with Django, on windows 7. I have installed python 2.7 and django 1.10 for the purpose. I made a sample project from windows powershell, and when i start the django server, as shown below, starting django server from powershell
when i go to the IP 127.0.0.1:8000/, it does not show me a django welcome page like the one below django server welcome page
All i see is a blank page. I have tried restarting the server many times, but never once, did i see the welcome page. What could be the problem here?
Not sure if this is the cause of the issue but maybe you want to do the database migration step as the error message suggested. Just run
python manage.py migrate
I have a Python3 website on IIS8 server and WindowsServer2012 and would like to add django to it. I have started learning django and made some small examplaes on my localhost and now want to integrate django into the IIS.
It is important to note that I just want to see that it works on my IIS and then turn it off, so that I can move all the site to django on localhost, while the current site is still functioning correctly.
I got confused regarding different ways. Where would be a good starting point for this integration (note, this is Windows Server 2012)?