[go: up one dir, main page]

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

Django Steps

This document provides a step-by-step guide for creating a Django project and web application, including setting up models, views, and URLs. It outlines the necessary files in a Django app, how to register models in the admin interface, and the process for creating a superuser. Finally, it emphasizes the importance of running migrations and starting the server to launch the application.

Uploaded by

pravinpatil0457
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)
10 views4 pages

Django Steps

This document provides a step-by-step guide for creating a Django project and web application, including setting up models, views, and URLs. It outlines the necessary files in a Django app, how to register models in the admin interface, and the process for creating a superuser. Finally, it emphasizes the importance of running migrations and starting the server to launch the application.

Uploaded by

pravinpatil0457
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/ 4

Django Easy Steps

For creating first project.


django-admin startproject firstproject

For Create first web application.


py manage.py startapp testapp

In Every app we have 7 files.


1.__init__.py: -
2.admin.py: -
3.apps.py: -
4.models.py: -
5.tests.py: -
6.urls.py: - this file we need to create.
7.views.py: -
We can run server after 6 steps
Step 1: - Models.py: we have to write class in the models.py file.
from django.db import models
class Task(models.Model):
Title=models.CharField(max_length=100)
Description=models.TextField(max_length=200)
Completed=models.BooleanField(default='True')
CreatedAt=models.DateTimeField()
Step 2: - Views.py : - We have to write ListView in view.py file.
from django.views.generic import ListView
from .models import Task
class TaskListView(ListView):
queryset=Task.objects.all()
Step 3: -In project url.py: we have to give path of url in urls .py, For
each new application need to give path.
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('demoapp/', include('DemoApp.urls')),
path('ass2app/',include("Ass2App.urls"))
]

Step 4: - In app urls.py: We need to create url.py file in every app


from django.urls import path
from .views import TaskListView
urlpatterns = [
path('ass2app/',TaskListView.as_view())
]
Step 5: - admin.py: - we need to register our model here.
from django.contrib import admin
from .models import Task,Book
admin.site.register(Task)

Setp 6: - setting.py: - we need to give app name in installed app


INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'DemoApp',
'Ass2App'
]

After this all steps we need to do migrations


1. py manage.py makemigrations
2. py manage.py migrate
How to create superuser
Command: py manage.py createsuperuser
Username:admin
Email:admin@gmail.com
Password:admin
Repass:admin
Superuser create sussfully:
Sreverstart py manage.py runserver

You might also like