Skip to content

You can see here, the simple addition operation with django-python in webpage at port 127.0.0.1:8000 || Author: K. VIGNESWAR SIDDU

Notifications You must be signed in to change notification settings

Vigneswarsiddu/python-django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-Django

You I will Explain all the steps one-on-one from scratch on how to create the simple addition operation with Django on the webpage at port http://127.0.0.1:8000/ - default Django port

Open the Command prompt

1. Check whether your machine is installed with the Python version
C:\Windows\System32>python --version
Python 3.10.5 if not, cmd: pip install python
2. Next, I need to create my virtual environment to install Django, because I don't want my entire machine to install on it.
3. cmd: mkvirtualenv test after you created your environment you can go to your directory and check whether it is created or not under your Cdrive:
image image
4. Here, I'm giving my virtual environment name as a test
5. If you have already created the virtual environment before you can simply type cmd: C:\Users\lenovo>workon test
6. So, from onwards it uses a test virtual environment to run all your commands. Now, install Django in your virtualenv test cmd: pip install django
7. now I need to create my webpage so that I need to create a projects file cmd: mkdir projects
8. cmd: django-admin startproject sidtronic -- Here I'm giving my project name as sidtronic, go to your dir and check for your project file created or not.
image
Inside your project file there will be manage.py file where your main server runs on this. and also there are other files:
1. urls.py 2. settings.py -- I will explain this later on.
image
To run my project in cmd prompt type:
9. (test) C:\Users\lenovo>cd projects
10. (test) C:\Users\lenovo\projects>cd sidtronic
Now check with dir the files inside your project:
11. (test) C:\Users\lenovo\projects\sidtronic>dir
image
12. Now open Visual Studio code, If not install please refer: https://code.visualstudio.com/download -- for both windows & linux
13. Now, click on open folder and import your project directory created on your CDrive.
image
14. Now I'm creating the app name called demoapp -- Note: It's an app, not the project, app we will use for to combine all the modules as the framework under the project.
15. To create demoapp run the command in a command prompt -- python manage.py startapp demoapp -- Note: It should run on test environment otherwise it occurs error. after creating you can check in your visual studio code of folder with name -demoapp
image

1. views.py

-- here views.py file will be there from demoapp, but not from your project file -- If you want you can create by create file -- views.py
Under this views.py we create or Implement the logic.

2. urls.py

-- It's very important beacuse the web server with runs from this as it works like the admin, whatever logic you implemented on views.py the urls path should be added to this. # Note you should create additional paths on the main project file, not in the demoapp -- if you create url in demoapp the server will show you as default.

3. Settings.py

This we will have DTL (Dashboard template language) -- where you can see different installed apps, and settings configurations for the web application.
image
Here in settings I need to change few things,
1. I need to add demo app into my installed apps in settings.py
image
2. I need to add my template folder where I do my HTML code workings -- for that I need to create folder with name templates in vs code. after that type command in settings.py -- under TEMPLATES [
'DIRS': [os.path.join(BASE_DIR,'templates')] ]
image
3. If you want you can change the time also - to Indian time by 'Asia/Kolkata'
image

Now, Let's implement the simple addition web page.

1. Firstly, I need to create home.html for my front end - view operations that view by the user.

2. base.html where we add background color as bgcolor. -- Here to work jinja, add extension.

NOTE: GET is used to fetch the data, POST is used to submit the data.
I'm attaching the image format of the inputs you can Understand Easily.

Inputs:

1. templates -> home.html

image
Here under home.html we extend the base.html with jinja {% extends 'base.html' %} -- as in base.html we will have our docHTML frontend view operation.

2. base.html

image

3. views.py

image

4. result.html

image

5. urls.py

image

OUTPUT:

To run the server of your web application go to command prompt and type cmd:
python manage.py runserver
image image image image

For Any Queries you can Contact Email Id: vigneswarsiddu07@gmail.com

About

You can see here, the simple addition operation with django-python in webpage at port 127.0.0.1:8000 || Author: K. VIGNESWAR SIDDU

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published