Simple list of Django command to create a web application

 Django shortcut note to create web application

Install python and check the version of python-pip(installed with python)

Python --version

Pip --version

Pip install virtualenvwrapper-win

Create enverment vituralenv test1

 

Now its time to install Django

pip install django(it takes some time)

To check version in cmd by django-admin –version

It will not work in new cmd

mkdir paisa(create folder for project)

Cd paisa (to move into folder)

django-admin startproject paisa (here pasia is project name)

Mave to project

By cd paisa

To run project on server it provide light server

python manage.py runserver (run every to see results)

open paisa folder in  text editor

to create on web page in text editor we cannot use because we have to enverment create before like vituralenv test1 to use this

workon test1

to create web page: python manage.py startapp helloworld

DTL(Django Template Langange)

 

 

MVT(model(data) view template(html,css javascript,DTL))

ORM(Object Relational Mapper)

Install postgresSQl and pgadmin(it is your database)

Password: xxxxx

Username:postgres

Port: xxxx

Install psycopg2 to connect postgres and python

pip install psycopg2 download using psycopg2 in cmd

ROM :used to create table without sql code

To create sign-in page:

It should be added in settings.py:

'alcutrofin.apps.AlcutrofinConfig',

 

DATABASES = {

    'default': {

        'ENGINE''django.db.backends.postgresql',

        'NAME''project name',

        'USER':'postgres',

        'PASSWORD':'xxxxx',

        'HOST':'localhost'

    }

}

In views.py:

from django.shortcuts import render,redirect

from django.http import HttpResponse

from django.contrib.auth.models import User,auth

from django.contrib import messages

 

To models to the database, you have to make migration

python manage.py makemigrations in cmd

To handle with an image in the database we need a library pillow

pip install pillow in cmd

create a migration file but migrated

to do this python manage.py sqlmigrate name 0001   in cmd (it only create sql query to run this use below.

to migrate python manage.py migrate                                                                                                                                                                                                                                                                                                                                             

to add an extra column to the table do remigration

by python manage.py makemigrations                                                                                                                                                                                                 Admin panel                                                                                                                     

to give value directly from page we superuser  

python manage.py createsuperuser      

username: xxxxxxxxxxxxxx

email: xxxxxxxxxxxxx@gmail.com                  

password: xxxxxxxxx

 

we need register in admin.py page to create template what we create.

To add all static files to project add all static files into a separate folder where you can find all static files here.

Then in Settings.py add:

STATICFILES_DIRS=[

Os.path.join(BASE_DIR, ‘name/static’)

]

STATIC_ROOT = os.path.join(BASE_DIR,’assests’)

In cmd to add assets to project:

python manage.py collectstatic

To get access to that files add

{% load static %}  in HTML file first line

Add specify that in “{% static ‘css/styles.css’ %}”


To add rich text editor in django like :


pip install django-ckeditor

and add from ckeditor.fields import RichTextField


Post a Comment

Previous Post Next Post

Featured post

Keyboard shortcutkeys for IntelliJ