Python Tutorial Coming Soon
Download Python
For Window
For Mac Os X
Download
How to check Python are install & check version also
- Step - Type Window+R button on your Computer or PC.
- Step- Type cmd/CMD and press enter. A black screen window opened called Command Prompt.
- Step- Type PYTHON/Python/python.
How To Intall Django FrameWork in Django
Note :- For installing django we need to install python latest version and all packages also. Links are given above. Your computer and PC are should connected to internet.
- Step- Open command prompt type pip install virtualenv
- Step- pip install django
How to create a Project in Python
Note:- create project on desktop to easily find. Below Bookcollection is an project name, You can choose any name which you want.
- Step- Open command prompt type cd desktop and press enter.
- Step- Type django-admin startproject Bookcollection and press enter.
Verify that Bookcollection named project created on desktop. In this project two file are created automatically. Firstone is Bookcollection and secondone is manage. Manage file extention are saved with ( .py ). Open Bookcollection here four file are created automatically.
- __init__
- settings
- urls
- wsgi
All file are saved with ( .py ) extention.
Now we need to run this project for what stuff are in it. Python are server based language. So we need server for run our project. Servers are not free but Python solve our problem, Python can run on local server in our computer or PC.
Run our project on server
- Step- Open command prompt type cd desktop and press enter.
- Step- Type cd Bookcollection and press enter.
- Step- Type python manage.py migrate and press enter
- Step- Type python manage.py runserver and press enter
After perform migration these all are shown.
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK
After perform runserver these all are shown
Performing system checks...
System check identified no issues (0 silenced).
August 10, 2018 - 19:28:19
Django version 2.1, using settings 'f.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Now command prompt open instructions. Here 127.0.0.1:8000 local server created in your computer. Do not close this command prompt window. If you close this window server are also closed, and we can't run our project.
- Step- Type 127.0.0.1:8000 in your browser url tab.
The install worked successfully! Congratulations! These message are shown on your browser front. Done our project are run.
How to create admin panel
Note:- open second command prompt window.
Type 127.0.0.1:8000/admin/ in browser url tab for admin pannel
Note:- open second command prompt window.
Type 127.0.0.1:8000/admin/ in browser url tab for admin pannel
- Step- Open command prompt
- Step- Type cd desktop and press enter.
- Step- Type cd Bookcollection and press enter.
- Step- Type python manage.py createsuperuser and press enter.
Username (leave blank to use 'pavilion'): username
Email address: user@gmail.com
Password: admin12345 (in command prompt password are blanked) password are not show here.
Password (again):admin12345
How to create python app
we are creating app for connecting our project , we need to create app in project file so.
- Step- Open command prompt and type cd desktop and press enter.
- Step- Type cd Bookcollection and press enter
- Step- Type django-admin startapp Home
app are created in Bookcollection project file
How to connect Python project to Python app or Create class in python
- step- Open models.py to your project and type is code
from django.db import models
# Create your models here.
class Books(models.Model):
title = models.CharField(max_length=80)
author = models.CharField(max_length=100)
isbn = models.CharField(max_length=30, unique=True)
url = models.URLField()
publisher = models.CharField(max_length=100)
def __str__(self):
return self.title+', '+self.author+', '+self.isbn+', +self.url+', '+self.publisher
return self.title+', '+self.author+', '+self.isbn+', +self.url+', '+self.publisher
2. step- Open admin.py and type this code
from django.contrib import admin
from .models import Books
# Register your models here.
admin.site.register(Books)
3. step- Open settings.py and type this code in 34 line
'Home.apps.HomeConfig',
Now save it all and open cmd type
- Step- open cmd and type cd desktop and press enter
- Step- Type cd Bookcollection and press enter
- Step- Type python manage.py makemigrations Home press enter
- Step- Type python manage.py migrate and press enter
- Step- Type python manage.py runserver and press enter
our project run on local server type 127.0.0.1:8000/admin to login admin panel. Here a class was created named Bookss.Here we can add list of some books.
Now create a urls.py file in Home app and type this code
from django.contrib import adminfrom django.urls import path,include
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('Home/',include('Home.urls')),
]
Note:-type this above code in Home urls don't confuse
comment your problem
ReplyDelete