#2 making your html templates
be rendered in your django project.
After creating your django project you will need to
insert html templates where your data will be displayed to the user. Before you
proceed make sure you have the following files in your main project’s folder:
First we must create an app that will handle all our
requests and will render our html pages.
We will write the *startapp* command to create our
app.
This will add another folder named tutorial to our project folder.
When you open the folder you will see the following
files:
We will then edit the settings.py file. Open the file
in your preferred text editor and we will edit it as followed:
Add the correct path to your templates folder.
We will then edit the urls.py of the main folder which
we created first in order to connect with our new app. Add the lines below to
your file:
As you can see we do not have a urls.py file in our
tutorial app. So we will create one containing the following lines:
We will then create a simple index.html file and store it in the templates folder:
You can create a file of your choice , this will just
be an example to be rendered as our
output.
Then now let us edit our views.py to create a function
to render our html page.
Now run your server and you are supposed to see your
html output.
This shows that our html has been rendered and we have
succeeded. Now you can add more lines to your html file to manipulate the
output.
Comments
Post a Comment