1 02 Django (Deploy in PythonAnywhere)
2
3 Highlight legend:
4
5 Add code
6 Remove code
7 My Screen look like
8 Existing code
9
10 First, ensure that the PSUSphere repository contains the latest version of the code. In the root directory of your
11 repository, alongside the '[Link]' file, there should be a file named '[Link]'. This file is crucial for
12 installing the necessary modules used in your project into the Python virtual environment on PythonAnywhere.
13
14 The '[Link]' file should list all the required Python packages and their versions, formatted like this:
15
16 asgiref==3.8.1
17 Django==4.2.11
18 Faker==24.4.0
19 python-dateutil==2.9.0.post0
20 six==1.16.0
21 sqlparse==0.4.4
22 typing_extensions==4.10.0
23
24 I. Specify allowed hosts
25
26 ¨ Modify projectsite/projectsite/[Link]
27
28 ALLOWED_HOSTS = []
29 ALLOWED_HOSTS = ['[Link]', '[Link]']
30
31 ¨ Commit Changes
32
33 $ git add .
34 $ git commit -m “modify allowed host”
35 $ git push
36
37 II. Create Pythonanywhere Account
38
39 ¨ Go to [Link]
40 ¨ Click "Create a Beginner account" button
41 ¨ username: [your-username]
42 ¨ email: [your email add]
43 ¨ password: [your password]
44 ¨ click "Register"
45 ¨ In Dashboard under Consoles, click "$Bash". This will load terminal in Pythonanywhere.
46
47 III. Setup repository in Pythonanywhere
48
49 ¨ In Bash terminal, create virtual environment in Pythonanywhere and activate it.
50
51 Syntax: virtualenv [virtual environment name]
52
53 $ virtualenv psusenv
54 $ source psusenv/bin/activate
55
56 ¨ Clone the project's repository into your virtual environment. You only need to use the 'clone' command once. For
57 subsequent updates to your codebase, use the 'pull' command instead. This ensures you retrieve the latest
58 version of your code from the repository.
59
60 $ git clone <your-git-repo-url>
61
62 $ git clone [Link]
63 $ ls
64 PSUSphere [Link] psusenv
65
66 $ cd PSUSphere/
67 projectsite [Link] [Link]
68
69 ¨ Install dependencies listed in [Link]
rev date: 2024-03 rev 00 1
70
71 $ pip install -r [Link]
72
73 IV. Configure Web App
74
75 ¨ Check version of python installed
76
77 $ python
78
79 Python 3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0] on linuxType "help", "copyright",
80 "credits" or "license" for more information.
81 >>> quit()
82
83 ¨ From Menu click “Web”
84 ¨ Click "Add a new web app" > Next > Click "Manual Configuration"
85 ¨ Select the version of your python > Next
86
87
88
89 ¨ Go to WSGI configuration file, click the psusphere_pythonanywhere_com_wsgi.py
90 ¨ Remove all existing code there and replace it with the code below.
91
92 import os
93 import sys
94
95 # path where you can find the [Link]
96 path = `/home/psusphere/PSUSphere/projectsite`
97 if path not in [Link]:
98 [Link](0, path)
99
100 [Link][`DJANGO_SETTINGS_MODULE`] = `[Link]`
101 from [Link] import get_wsgi_application
102 from [Link] import StaticFilesHandler
103 application = StaticFilesHandler(get_wsgi_application())
104
105 ¨ Click “Save”
106 ¨ Go to Virtualenv, click the “Enter path to a virtualenv, if desired”
107 ¨ Set virtual environment path: /home/psusphere/psusenv
108 ¨ Click the “Reload [Link]” button above.
109
110 To verify whether the project has been successfully deployed, open your web browser and navigate to the following
111 URL: [Link]
rev date: 2024-03 rev 00 2