You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
13. Now, click on open folder and import your project directory created on your CDrive.
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
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.
Here in settings I need to change few things,
1. I need to add demo app into my installed apps in settings.py
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')] ]
3. If you want you can change the time also - to Indian time by 'Asia/Kolkata'
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
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
3. views.py
4. result.html
5. urls.py
OUTPUT:
To run the server of your web application go to command prompt and type cmd: