1
2# --------- Basic steps for working with Django on a MAC ---------- #
3
4 1º - Create a virtual environment by giving this command:
5
6 >> python3 -m venv "name_of_env"
7
8
9 2º - Activate this virtual environment:
10
11 >> source "name_of_env"/bin/activate
12
13
14 3º - Now you can install Django:
15
16 >> pip3 install django
17
18
19 4º - To initiate a project in Django:
20
21 >> django-admin startproject "projectName"
22 >> cd projectName
23
24
25 5º - To run the server, you need to go to the directory containing
26 manage.py and from there enter the command:
27
28 >> python3 manage.py runserver
29
30
31 6º - To create a basic app in your Django project you need to go
32 to the directory containing manage.py and from there enter
33 the command:
34
35 >> python3 manage.py startapp "projectAppName"
36
37
38 7º - You need to include the app in our main project so that
39 urls redirected to that app can be rendered. Move to
40 "projectName" -> "projectName" -> urls.py and change the
41 following:
42
43
44from django.contrib import admin
45from django.urls import path, include
46
47urlpatterns = [
48 path('admin/', admin.site.urls),
49 # Enter the app name in following syntax for this to work
50 path('', include("projectApp.urls")),
51]
52
53
1# start by installing django by typing the following command
2
3python -m pip install Django
4
5# you can check if it worked by typing
6
7python3 -m django --version # for mac
8
9python -m django --version # for windows
10
11# when that works you can start your project by
12
13django-admin startproject your_project_name
14
15# then you can start your first app by
16
17django-admin startapp your_app_name
18
19# before you can run it, you need to add the app to the project
20
21# go to the folder your_project_name and open settings.py and scroll down until you see this
22
23INSTALLED_APPS = [
24 'django.contrib.admin',
25 'django.contrib.auth',
26 'django.contrib.contenttypes',
27 'django.contrib.sessions',
28 'django.contrib.messages',
29 'django.contrib.staticfiles',
30]
31
32# then go to the folder your_app_name and open apps.py and copy the class name
33
34# when you did that, add the following line to installed apps
35
36'your_app_name.apps.the_class_name_you_just_copied'
37
38
39# happy coding!