Django A
Django A
03-08 ----------------------
path('', include('home.urls'))
path("",views.index,name='my_app'),
path("about",views.about,name='about'),
path("services",views.services,name='services'),
path("contact",views.contact,name='contact')
def about(request):
return HttpResponse('this is about page')
def services(request):
return HttpResponse('this is services page')
def contact(request):
return HttpResponse('this is contact page')
19. save everything, copy the link from the terminal and paste in the browser
20. now, create two folders in the parent project folder by the name template and
static
static folder saves images
return render(request,'index.html')
'DIRS': [BASE_DIR/'templates'],
04-08 -----------------
29. if the admin page does not load, in settings.py under installed_apps, add your
app name at the end
'my_app',
{% tag_name parameter %}
{% extends 'base.html' %}
{% block title %} Home {% endblock title %}
40. paste these lines at the very top and remove the html, head and body tags only
leaving the actual code (code after body)
41. in the place of body open and close tag, paste this
42. as we want the navbar in all of the pages, we have created a base.html file and
pasted the navbar code which is common fo all pages.
and we are passing this template in all the webpages and optimizing the code.
43. create a contacts.html file and paste this at the beginning of the file
{% extends 'base.html' %}
{% block title %} Contact {% endblock title %}
enclose all the html code within this tag i.e., forms, buttons, divs etc
45. we now have two pages up and running - home and contact page.
we can now navigate to these pages with the navbar
09-08 -----------------
def __str__(self):
return str(self.name)
52. load contact page by running the server from the terminal
53. in contact.html, paste this line after the contact-form
54. in terminal,
then,
then,
55. in contact page, enter details in the input fields and check if it reflects in
the database
if it does not reflect, then a form is not created in contact.html that holds all
these values.
contact table is created now, after making migrations
56. assign an id to all the input fields, so it can be accessed by the contact
method defined in views.py
</div>
57. now, load contact page and enter details and press the submit button
58. check database, the entered details are reflected in the database.