0% found this document useful (0 votes)
10 views2 pages

Setting Up a Django Project and App

This document provides a step-by-step guide on setting up a Django project and creating a Django app. It outlines the necessary commands to install Django, create a project, and add an app, along with explanations of key files generated during the setup. Additionally, it includes instructions for creating a simple view and linking it to a URL route within the app.

Uploaded by

Zoubaida Helali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Setting Up a Django Project and App

This document provides a step-by-step guide on setting up a Django project and creating a Django app. It outlines the necessary commands to install Django, create a project, and add an app, along with explanations of key files generated during the setup. Additionally, it includes instructions for creating a simple view and linking it to a URL route within the app.

Uploaded by

Zoubaida Helali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

First of all: SET UP DJANGO:

Open directory
Open Terminal
pip install django
***********************RESTART TERMINAL**********
CREATE A DJANGO PROJECT:
1: django-admin startproject project_name
--->
OUTPUT:generation of a new directory that contains a banch of files that are
generated by django
****************************************
_init_.py:a special file that tells python to treat this file like a python
package.

[Link]/[Link]: configuration files that allows django to communicate with the web
server( we won't deal with these files)

[Link]: install django application, plugins, middleware, & modify database


engines.

[Link]: configuration of URL routes to direct django apps

[Link]: special file that acts like a command line tool, allows us to run
special commands like, make database migrations, run our python server, creating
users for our admin panel ...

***************************************
If we want to have any executable code or be able to see the website appearing we
need to create something known as a Django app
NB: A DJANGO APP IS MEANT TO BE A STANDALONE APPLICATION THAT WE CAN PLUG AND PLAY
(move it from a project to another)
// DJANGO APPS contains :
* database models
* views/routes
* templates
* other stuff ..
****************************************
CREATE A DJANGO APP:
2.1: cd to the django project directory
2.2: python [Link] startapp app_name ( app created)
TO LINK THIS APP TO THE DJANGO PROJECT WE NEED TO ADD THE APP NAME TO THE
[Link] OF THE PROJECT
2.3: create a [Link] file : where we gonna create diffent URL routes and connect
them to our

TO CREATE A VIEW WE TYPE :

from [Link] import render, HttpResponse

def home(request):
return HttpResponse("Hello World")

to connect this view with a url :

@[Link] :
from [Link] import path
from . import views
urlpatterns =[
path("", [Link], name="home")
]

now after configuring the url OF our app, we need to configure the url TO our app

You might also like