The recommendation is to read this document completely before starting and also read the text from the tutorial completely before starting to write code.
You will encounter a lot of problems if you jump right in and start cutting and pasting.
The rest of theis document is here to help you with problems you might encounter while building the tutorial on PythonAnywhere.
python manage.py runserver
If you are not in your virtual environment in a bash shell on PythonAnywhere
lots of things will fail. You will not have access to the correct version
of Python and you will not have a proper installation of Django. You can always
check which python you are running using the
In the example below we are running Python 2.7.12 (bad) and Django 1.11.26 (very bad) without the virtual environment and once we activate into the virtual environment we are using Python 3.6 and Django 3.1.
17:33 ~ $ python --version Python 2.7.12 17:33 ~ $ python -m django --version 1.11.26 17:33 ~ $ workon django3 (django3) 17:33 ~ $ python --version Python 3.6.9 (django3) 17:36 ~ $ python -m django --version 3.1.1 (django3) 17:33 ~ $
Each time you start a new bash shell, you need to type
workon django3. If you
leave and come back to a shell that is still running, if you see the '(django3)'
in your prompt - you do not have to re-run the
workon command. It just needs
to be done once per shell.
There are several errors that you might get if your virtual environment is not activated:
The problem with these errors is that you think you are supposed to edit files
settings.py but the files are already just fine, you are
just using the wrong versions of software.
First and most important - you should not ever change the contents of the
The file is built by Django for you and does not need to be changed.
However, if you open
manage.py in the PythonAnywhere text editor even to look at it,
it will show a little red "X" on line 16 or 17 indicating a syntax error.
The problem (much like the virtual environment problem) is the wrong version of Python. The text editor is looking at the file as a Python 2.x file and not as a Python 3.x file. So the file shows a syntax error.
Do not fix this error.
If the error really bothers you, edit the first line of the file and change
python3 and save
the file. The error will magically disappear.
Do not make any other changes to the file.
If you came here after you tried to fix the syntax error and made it worse, simply look closely at every line of the correct file and fix your file. Usually the problem is indentation, a line has been deleted or something was moved around.
SyntaxErrorin 'manage.py' in the shell
check identifies errors, do not go on to the rest of the assignment
once you can run
check and there are no errors. If you see this error:
python manage.py check File "manage.py", line 17 ) from exc ^ SyntaxError: invalid syntax
Do not edit your
manage.py file - the problem is never in that file.
There are several possible reasons for this:
Just as a note, you never run the
runserver command on PythonAnywhere. Often the
tutorials have you make a bunch of changes to yout files and then tell you to do:
python3 manage.py runserver
This functionality is replaced by the "reload" button on your Web tab. So
if you are reading any Django instructions that say to do a
runserver, instead do a
python3 manage.py check
And then reload the application in the PythonAnywhere Web tab. There is a short cut to relead your application on the PythonAnywhere file editor. It is a little icon in the upper right of the editor that reloads the application. Usually you save the file, press reload and then check if your application worked.
localhostURLs on PythonAnywhere
Usually, right after the tutorial tells you to
python manage.py runserver it
tells you to navigate to a url that looks like:
Once you have reloaded your application you need to go to the URL that PythonAnywhere has assigned to your application.
If the tutorial tells you to go to a URL like
polls to your URL.
You do not need to add
mysite to your URL - this is all captured
in the settings under the 'Web' tab in the PythonAnywhere user interface.
If your application passed a
check but fails to
load or reload, you might get an error message that looks
If you get an error, you will need to look through the error logs
Web tab on PythonAnywhere:
First check the
error log and then check the
Make sure to scroll through the logs to the end to find the most recent error.