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
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?
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.
The Server is started in pycharm but in browser its showing like above pictures
I am new to Django Framework and I just installed pycharm now.
Can any one please help me out from this??
I have been working on a localhost copy of my Django website for a little while now, but finally decided it was time to upload it to PythonAnywhere. The site works perfectly on my localhost, but I am getting strange errors when I do the initial migrations for the new site. For example, I get this:
mysql.connector.errors.DatabaseError: 1264: Out of range value for
column 'applied' at row 1
'applied' is not a field in my model, so this error has to be generated by Django making tables for its own use. I have just checked in the MySQL manager for my localhost and the field 'applied' appears to be from the table django_migrations.
Why is Django mishandling setting up tables for its own use? I have dropped and remade the database a number of times, but the errors persist. If anyone has any idea what would cause this I would appreciate your advice very much.
My website front end is still showing the Hello World page and the Admin link comes up with a page does not exist error. At this stage I am going to assume this is related to the database errors.
EDIT: Additional information about why I cannot access the front-end of the site:
It turns out when I am importing a pre-built site into PythonAnywhere, I have to edit my wsgi.py file to point to the application. The trouble now is that I don't know exactly what to put there. When I follow the standard instructions in the PythonAnywhere help files nothing seems to change. There website is also seems to be very short on detailed error messages to help sort it out. Is there perhaps a way to turn off their standard hello world placeholder pages and see server error messages instead?
As it says in my comment above, it turns out that the problem with the database resulted from running an upgrade of Django from 1.8 to 1.9. I had forgotten about this. After rolling my website back to Django 1.8, the database migrations ran correctly.
The reason why I could not access the website turned out to be because I had to edit the wsgi.py file, but I was editing the wrong version. The nginx localhost web server I was using keeps it in the different folder location than PythonAnyhwere's implementation. I uploaded the file from my localhost copy and edited it according to the instructions on PythonAnywhere's help system without realizing it was not being read by PythonAnywhere's server. What I really needed to do was edit the correct file by accessing it through the web tab on their control panel. Once I edited this file, the website front end began to work as expected.
This issue occurred for me as well on version 1.10 with a brand new project. I found that if you use the recommended driver and the connector in the documentation, the migration works without issues.
If you don't feel like reading the docs, in breif:
Install MySQLdb for python 2.7 or mysqlclient for python 3.3+
Modify your settings.py file. In the DATABASES dictionary set:
'ENGINE': 'django.db.backends.mysql',
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)?