Wednesday, October 28, 2020

import * working method

 

create a file on student.py

========================


class Person:

  def __init__(self, name, age):

    self.name = name

    self.age = age



def anil_test(i):

    print("this is working"+i)


create another file test.py

======================

#from student import anil_test,Person

from student import *



anil_test("anil")

p1 = Person("John", 36)


print(p1.name)

print(p1.age)


Django models test

 Django models test...

======================

.in models.py file

class student(models.Model):

    student_sno = models.IntegerField();

    student_name = models.CharField(max_length=256);

    student_father_name= models.CharField(max_length=256);


class student_class(models.Model):

    student = models.ForeignKey(student,on_delete=models.CASCADE) 


python manage.py makemigrations your_app


python manage.py sqlmigrate your_app 0001


python manage.py migrate


python .\manage.py shell



in db shell

=====================

from chess2.models import student, student_class

Django html tags display

 Django html tags display:

========================

By writing html tags you can achieve the output 


go into views.py file


def menu(request):

    return HttpResponse("<h1>This is working menu</h1>");

django installation process

 django installation process:

=============================


pip install virtualenvwrapper-win

mkvirtualenv test

pip install django


django-admin --version


mkdir yourfolder


cd yourfolder


django-admin startproject yourprojectname


python manage.py runserver



to create virtual environment in vscode:

=======================================

workon "base"


python manage.py startapp yourapp



creating your app:

=======================

create urls.py in your app


urlpatterns=[

path('',views.home,name='home')

]


go into views.py

add :from django.http import HttpResponse


create a function home


def home(request):

return HttpResponse("we are into our own page");


go into urls project:

add below line


path('',include('yourapp.urls'))





python class topic video