Django Project and Subproject-Topic 1 Lab
Django Project and Subproject-Topic 1 Lab
FRAMEWORK AND
INSTALLATION
Installation
1. Go to https://www.python.org/
➢ Install Python3
2. Create new folder - example project_wad
3. Get into the project using command prompt
➢ f
How to create django project
a. manage.py
➢ help us to execute commands on our terminal. Don’t EDIT
this file!
b. settings.py
➢ contains some important configuration settings for our
new project, for example the database that we use. We will
use default settings first but at the end of the course we
might change a little bit (for deployment subject)
c. urls.py
➢ contains directions for where users should be routed after
navigating to a certain URL. We will change this a lot
Important files
b. settings.py
➢ contains some important
configuration settings for
our new project, for exam
ple the database that we
use. We will use default
settings first but at the
end of the course we
might change a little bit
(for deployment subject)
Important files
c. urls.py
➢ contains directions for where users should be routed after
navigating to a certain URL. We will change this a lot
Create subproject
• In a Django project (Personal_Hompage) you can have multiple subprojects,
eg: traveloka might have a flight subprojects, hotels subprojects etc..
urlpatterns = [
path("", views.index, name="index"),
]
Add codings inside urls.py in the subproject/app folder
urlpatterns = [
path("", views.index, name="index"),
]
Setup that you need to do
Add codings inside urls.py in the personalhomepage
urlpatterns = [
path('admin/', admin.site.urls),
path(‘my_page/',include('homepage.urls'))
]
Setup that you need to do
3. Create folder templates in subproject (hello_subproject)
4. In the templates folder, create a html file which is index.html
5. Create design for your main page
Setup that you need to do
6. Inside views.py in hello_subproject add the following code
def index(request):
return render (request,"index.html")
Setup that you need to do
7. Save document (setting, urls, view, html )
8. Runserver using command prompt
➢ python manage.py runserver
Setup that you need to do
Try to add page about.
def about(request):
return render (request,“about.html")