Difference between revisions of "Django in PythonAnywhere"
(→Using Your WebApp) |
(→Using Your WebApp) |
||
(9 intermediate revisions by the same user not shown) | |||
Line 42: | Line 42: | ||
[[File:PythonAnywhere8.png]] | [[File:PythonAnywhere8.png]] | ||
+ | |||
+ | This section provides you with '''go to directory''' links to access the '''Source Code''' for your webapp. | ||
+ | |||
+ | This is a screenshot of the '''File''' section of PythonAnywhere: | ||
+ | |||
+ | [[File:PythonAnywhere9.png]] | ||
+ | |||
+ | While you are in the '''Files''' section, before some of the features work you need to run a command so click the 'open bash console' button and type: | ||
+ | |||
+ | [[File:PythonAnywhere12.png]] | ||
+ | |||
+ | If this generates errors, you might need to run 'python3.8 manage.py migrate'. | ||
+ | |||
+ | Back on the Dashboard, the next important section is the 'Security' section, you will need to force HTTPS for it to work within college: | ||
+ | |||
+ | [[File:Force HTTPS.png]] | ||
+ | |||
+ | =Running django-admin commands= | ||
+ | To create an internal app you will need to run a django-admin command. you need to find the '''Open bash console here''' button: | ||
+ | |||
+ | [[File:PythonAnywhere10.png]] | ||
+ | |||
+ | You can then enter the following command to create an internal app called '''MyApp''': | ||
+ | |||
+ | [[File:PythonAnywhere11.png]] | ||
+ | |||
+ | If this generates errors, you might need to run 'python3.8 django-admin.py StartApp MyApp'. | ||
+ | |||
+ | This method can also be used to run other '''django-admin''' commands. | ||
+ | |||
+ | =Running django management commands= | ||
+ | |||
+ | Using the console, you could type: | ||
+ | |||
+ | [[File:PythonAnywhere12.png]] | ||
+ | |||
+ | If this generates errors, you might need to run 'python3.8 manage.py migrate'. | ||
+ | |||
+ | This would perform the '''migrate''' command. Other commands could be '''createsuperuser''', '''makemigrations''' and so on. |
Latest revision as of 14:09, 1 December 2020
Contents
Setup
Go to the [PythonAnywhere] website. It is an online python development environment. If you click the signup button you will see:
Click to Create a Beginner Account. Then complete the registration process. The Beginner Account will allow you to create one free django web app.
Creating a Django Web App
Now on the Dashboard you should see the 'Web App' section:
Click to open the Web Tab, and you should see this screen:
Click Add a new web app to start the process of creating a django app. The first screen will be:
This is just telling you that the basic account can only support this type of URL. It will be fine to use this and you can just click the Next button.
The next screen will allow you to select the framework you wish to use, click Django. This will then produce a list of Python versions, click the highest number for example 3.8 is the current python version:
Finally, when you click on the Python version the following screen will be displayed:
At this point you can change your project name, the default is 'mysite'. But you should leave the directory to the current value. Click Next to complete the process.
Using Your WebApp
When you make a change to your django app, you will need to Reload it in PythonAnywhere. The screenshot below shows this button:
The second button in the above screenshot will keep your django app active for the next 3 months. Because we are using a free account, it will disable your webapp after a 3 month period and this button will reset that period.
The next important section is labelled Code
This section provides you with go to directory links to access the Source Code for your webapp.
This is a screenshot of the File section of PythonAnywhere:
While you are in the Files section, before some of the features work you need to run a command so click the 'open bash console' button and type:
If this generates errors, you might need to run 'python3.8 manage.py migrate'.
Back on the Dashboard, the next important section is the 'Security' section, you will need to force HTTPS for it to work within college:
Running django-admin commands
To create an internal app you will need to run a django-admin command. you need to find the Open bash console here button:
You can then enter the following command to create an internal app called MyApp:
If this generates errors, you might need to run 'python3.8 django-admin.py StartApp MyApp'.
This method can also be used to run other django-admin commands.
Running django management commands
Using the console, you could type:
If this generates errors, you might need to run 'python3.8 manage.py migrate'.
This would perform the migrate command. Other commands could be createsuperuser, makemigrations and so on.