Академический Документы
Профессиональный Документы
Культура Документы
In the urls.py of main folder sugandhi add this home page entry
urlpatterns = [path('',include('calc.urls'))]
In the templates list of settings.py of main folder sugandhi add a new list in dirs
=> [os.path.join(BASE_DIR,'Templates')]
Change the return function of views.py in calc folder from return HttpRes.... to =>
return render(request,'home.html')
Dynamic Content => In the return function of views.py after 'home.html' add the
dictionary => {'name':'Aayush'}
In home.html webpage write => {{name}} in the tag
In home.html we have created a form which is taking 2 inputs from the user and
calcuating sum of it.
When user clicks on the submit button the request will go on the add(which is the
form action)
This add function is present in the views.py, in this function we are fetching the
values that we get from the user.
This function will return the value of sum to return.html .
Here we have used GET Method
Path is HTML File -> urls.py -> views.py -> html file
Use csrf token to send the data from client to the Server
a) Create a folder name travello in the same heirarchy of the main folder sugandhi
Create new app/folder => python manage.py startapp (nameofapp -> travello)
Create urls.py in travello app/folder
In urls.py of travello write the snippet
a)from django.urls import path
b)from . import views
c)urlpatterns = [
path('',views.index,name='index')
]
d)create the function index in views.py => see views.py for details
In settings.py of the main folder bankloan we will find we will find the Installed
Apps named list update this list to
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'BankLoans.apps.BankloansConfig',
]
In the urls.py of main folder sugandhi add this home page entry
urlpatterns = [path('',include('travello.urls'))]
b) Also create a new folder static(which contains all the html css and jss files of
the website) This folder is in the same heirarchy of the travello
c) In settings.py of main folder sugandhi add a new path for the static folder, add
a new list beneath the list STATIC_URL,
STATICFILES_DIRS = [os.path.join(BASE_DIR,'sugandhi/static')]
d) Django wants to put all of these static files in its own folder which is done by
creating a new list
STATIC_ROOT = os.path.join('BASE_DIR','assets')
e) But django should know that he has to create a folder name assets
on cmd type the command python manage.py collectstatic
f) In every line of the html file which contains the href tag, which is the link
either to the css file or to any new page
href = {%static .......original-href-tag.... %} , same for src and styles
plugins,beware of the background image
g) Also, in every html file write {% load static %} on the 1st line
c)For loop in django Since we cant do this as no. of destn is also dynamic, we will
create a loop , see in index.html how for loop works
d)But the biggest problem is dynamic addition of images, jinja cant be placed
inside another jinja
To overcome this write {% static "images" as baseUrl%} on the top of the HTML
file
<img src="{{baseUrl}}/{{dest.img}}" alt="">