0% found this document useful (0 votes)
7 views

Module-1-L5. Startproject and Startapp

The document provides a step-by-step guide on starting a Django project and app using the django-admin command. It outlines the structure of a Django project and app, detailing the purpose of various files such as settings.py, urls.py, and views.py. Additionally, it includes instructions on how to configure the app within the project settings and create a simple view that returns a response.

Uploaded by

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

Module-1-L5. Startproject and Startapp

The document provides a step-by-step guide on starting a Django project and app using the django-admin command. It outlines the structure of a Django project and app, detailing the purpose of various files such as settings.py, urls.py, and views.py. Additionally, it includes instructions on how to configure the app within the project settings and create a simple view that returns a response.

Uploaded by

hod.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Module 1

Start project & start app


Starting a Project
 django-admin.exe startproject myproject

 This command is used to create a new Django project.

 A Django project is a collection of settings and configurations that define a specific

Django instance, including the project settings, URL configurations, and WSGI

configuration.

 django-admin.exe startproject myproject


Starting a Project
 myproject/
 manage.py
 myproject/
 __init__.py
 settings.py
 urls.py
 wsgi.py
 asgi.py
Starting a Project
 myproject/: This outer directory is just a container for your project. Its name doesn’t
matter to Django and you can rename it to anything you like.
 manage.py: A command-line utility that lets you interact with this Django project in
various ways.
 myproject/: This inner directory is the actual Python package for your project. Its
name is the Python package name you’ll need to use to import anything inside it (e.g.,
myproject.settings).
 __init__.py: An empty file that tells Python that this directory should be considered a
Python package.
 settings.py: Settings/configuration for this Django project.
 urls.py: The URL declarations for this Django project; a “table of contents” of your
Django-powered site.
Starting a Project
 wsgi.py: An entry-point for WSGI-compatible web servers to serve your project.
 asgi.py: An entry-point for ASGI-compatible web servers to serve your project.
Starting a App
 django-admin.exe startapp
 This command is used to create a new Django app within your project. A Django app is
a web application that does something, such as a blog system, a database of public
records, or a simple poll application.
 django-admin.exe startapp myapp
 myapp/
 __init__.py
 admin.py
 apps.py
 migrations/
 __init__.py
 models.py
 tests.py
 views.py
Starting a App
 __init__.py: An empty file that tells Python that this directory should be considered a
Python package.
 admin.py: A place to register models with the Django admin site, so you can manage
them through the admin interface.
 apps.py: A configuration file for the app. Django uses it to reference the app and its
configuration.
 migrations/: A directory that will store migration files. Migrations are how Django
stores changes to your models (and thus your database schema) over time.
 __init__.py: An empty file that tells Python that this directory should be considered a
Python package.
 models.py: A place to define your models. Models are the single, definitive source of
information about your data. They contain the essential fields and behaviors of the data
you’re storing.
 tests.py: A place to put your tests.
 views.py: A place to put your views. Views are responsible for processing a request and
returning a response.
How to use these commands together
1. django-admin startproject myproject
2. cd myproject
3. django-admin startapp myapp
4. Open (myproject/settings.py)
INSTALLED_APPS = [
...
'myapp',
]
How to use these commands together
1. # myapp/views.py
2. from django.http import HttpResponse
3. def hello(request):
4. return HttpResponse("Hello, world!")
How to use these commands together
1. # myproject/urls.py
2. from django.contrib import admin
3. from django.urls import path
4. from myapp import views
5. urlpatterns = [
6. path('admin/', admin.site.urls),
7. path('', views.hello, name='hello'),
8. ]
How to use these commands together
1. # myproject/settings.py
2. INSTALLED_APPS = [
3. 'django.contrib.admin',
4. 'django.contrib.auth',
5. 'django.contrib.contenttypes',
6. 'django.contrib.sessions',
7. 'django.contrib.messages',
8. 'django.contrib.staticfiles',
9. 'myapp',
10. ]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy