├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 London App Developer Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Build a Backend REST API with Python & Django - Beginner 2 | 3 | This is the supplementary cheat sheet document for our course: [Build a Backend REST API with Python & Django - Beginner](https://londonapp.dev/c1) 4 | 5 | 6 | 7 | - [Git](#git) 8 | - [SSH Key Management](#ssh-key-management) 9 | - [Virtual Environments](#virtual-environments) 10 | - [Django Management Commands](#django-management-commands) 11 | - [Vagrant](#vagrant) 12 | - [Terminal / GitBash Commands](#terminal-gitbash-commands) 13 | 14 | 15 | 16 | ## Git 17 | 18 | Use the below Git commands in the Windows Command Prompt or macOS Terminal. 19 | 20 | **Configure default email and name** 21 | 22 | *Note: This only needs to be done the first time you use Git on your machine* 23 | 24 | ``` 25 | git config --global user.email "your@email.com" 26 | git config --global user.name "Your Name" 27 | ``` 28 | 29 | **Initialise a new Git repository** 30 | 31 | ``` 32 | git init 33 | ``` 34 | 35 | **Commit changes to Git** 36 | 37 | ``` 38 | git add . 39 | git commit -am "Commit message" 40 | ``` 41 | 42 | **Set Git remote** 43 | 44 | *Note: This only needs to be done once, the details are provided by GitHub after creating a new project* 45 | 46 | ``` 47 | git remote add origin 48 | git push -u origin master 49 | ``` 50 | 51 | **Push changes to GitHub** 52 | 53 | ``` 54 | git push origin 55 | ``` 56 | 57 | ## SSH Key Management 58 | 59 | The below commands are used to manage SSH keys on your local development machine. 60 | 61 | **Checking for existing SSH key** 62 | 63 | ``` 64 | ls ~/.ssh/ 65 | ``` 66 | 67 | **Print contents of public key** 68 | 69 | ``` 70 | cat ~/.ssh/id_rsa.pub 71 | ``` 72 | 73 | **Generate new SSH key on your local machine** 74 | 75 | ``` 76 | ssh-keygen -t rsa -b 4096 -C "EMAIL ADDRESS" 77 | ``` 78 | 79 | 80 | ## Virtual Environments 81 | 82 | The below commands are used for managing Virtual Environments using Python3-env. Use these commands when connected to your Vagrant server. 83 | 84 | **Create new environment** 85 | 86 | ``` 87 | python -m venv ~/env 88 | ``` 89 | 90 | **Activate virtual environment** 91 | 92 | ``` 93 | source ~/env/bin/activate 94 | ``` 95 | 96 | **De-activate virtual environment** 97 | 98 | ``` 99 | deactivate 100 | ``` 101 | 102 | **Install requirements from requirements.txt** 103 | 104 | *Note: Virtual environment must be activated* 105 | 106 | ``` 107 | pip install -r requirements.txt 108 | ``` 109 | 110 | ## Django Management Commands 111 | 112 | **Create new Django project** 113 | 114 | ``` 115 | django-admin.py startproject profiles_project . 116 | ``` 117 | 118 | **Create new Django app** 119 | 120 | ``` 121 | python manage.py startapp profiles_api 122 | ``` 123 | 124 | **Start Django development server** 125 | 126 | ``` 127 | python manage.py runserver 0.0.0.0:8000 128 | ``` 129 | 130 | **Create database migrations file** 131 | 132 | ``` 133 | python manage.py makemigrations 134 | ``` 135 | 136 | **Run migrations** 137 | 138 | ``` 139 | python manage.py migrate 140 | ``` 141 | 142 | **Create new superuser** 143 | 144 | ``` 145 | python manage.py createsuperuser 146 | ``` 147 | 148 | ## Vagrant 149 | 150 | These commands are used for managing Vagrant using the GitBash or Terminal windows. 151 | 152 | **Initialise Vagrant on project** 153 | 154 | ``` 155 | vagrant init ubuntu/bionic64 156 | ``` 157 | 158 | **Start Vagrant box** 159 | 160 | ``` 161 | vagrant up 162 | ``` 163 | 164 | **Connect to Vagrant box** 165 | 166 | ``` 167 | vagrant ssh 168 | ``` 169 | 170 | **Disconnect from Vagrant box** 171 | 172 | *Note: This command is a standard linux command for ending an SSH session* 173 | 174 | ``` 175 | exit 176 | ``` 177 | 178 | **Stop Vagrant box** 179 | 180 | ``` 181 | vagrant halt 182 | ``` 183 | 184 | **Remove Vagrant box** 185 | 186 | ``` 187 | vagrant destroy 188 | ``` 189 | 190 | **Update Vagrant box image** 191 | 192 | *Note: you must rebuild the image after updating* 193 | 194 | ``` 195 | vagrant box update 196 | ``` 197 | 198 | ## Terminal / GitBash Commands 199 | 200 | Change directory 201 | 202 | ``` 203 | cd /directory_name 204 | ``` 205 | 206 | Change to parent directory 207 | 208 | ``` 209 | cd .. 210 | ``` 211 | --------------------------------------------------------------------------------