FIrst i created project, then created an app Registered the app into the setttings.py file Then first created the view in the app, then add url to the urls.py file in the app If more urls are to be added and multiple apps within the project use include and make urls.py in own app Then made the html file in index directory and worked there. The function in views class takes the request as parameter and returns either HttpResponse or a render object. Render or render_to_response are somehow similar and we give them the request, the file to open i.e. html file and then the variables to be sent with {“temp_name”: my_var}. We edit the html file by putting in the variables as {{ temp_name }} and this works.
TAda… :)
Now use of filters in these variables as {{ temp_name | lower }} makes the variable appear in lowercase
More filters are: capfirst, upper
Very tasty filter is pluralize:
{{ temp_num }} {{ temp_num|pluralize : “y, ies” }}
Another one is XSS filter: It helps escape HTML chars. it makes < to < , > to > and so on.
This is done by {% autoescape on %} {% endautoescape %} and {% autoescape off %} and comes the safe filter that makes the variable not escape since it is considered safe inside autoescape on.
simply we can make escapes with escape filter. {{ var1 |escape }}
linebreaks filter as like
tag
TADA this too done ;) :D
Now to make any changes to additional links, they must be added into the urls.py file and when we add an url to urls.py file, we can give them a name so when referencing using the < a href="{% url ‘url_name’ %}">Hello can be used To make sure to make it cleaner we can make two htmls one base.html to store core html and index.html to store the template type html code only . Since we will {% extends base.html %} into index.html, they basically act as one.
TADA this one done too.. :) :)
To work with css and static files, need to add STATIC_DIRS in settings.py file and os.path.join to use these static files in any html file , {% load staticfiles %} must be first included
This way css works as well. :DNow time to write the models ie the database to work with: So here I created few models to start a dating site with a user, his partner should be like, his education as well as his interests. So from django.db import models The classes are created where we pass models.Model as argument and specify the types of the field to work with. We made migrations and just migrated the changes into the database.