Category: D jango

  • Django Add Master Template

    The extends Tag In the previous pages we created two templates, one for listing all members, and one for details about a member. The templates have a set of HTML code that are the same for both templates. Django provides a way of making a “parent template” that you can include in all pages to…

  • Django Add Link to Details

    Details Template The next step in our web page will be to add a Details page, where we can list more details about a specific member. Start by creating a new template called details.html: my_tennis_club/members/templates/details.html: Add Link in all-members Template The list in all_members.html should be clickable, and take you to the details page with the ID of…

  • Django Prepare Template

    Create Template After creating Models, with the fields and data we want in them, it is time to display the data in a web page. Start by creating an HTML file named all_members.html and place it in the /templates/ folder: my_tennis_club/members/templates/all_members.html: Do you see the {% %} brackets inside the HTML document? They are Django Tags, telling Django to perform some…

  • Django Update Model

    Add Fields in the Model To add a field to a table after it is created, open the models.py file, and make your changes: my_tennis_club/members/models.py: As you can see, we want to add phone and joined_date to our Member Model. This is a change in the Model’s structure, and therefor we have to make a migration to tell Django that it…

  • Django Delete Data

    Delete Records To delete a record in a table, start by getting the record you want to delete: x will now represent the member at index 5, which is “Jane Doe”, but to make sure, let us see if that is correct: This should give you this result: ‘Jane’ Now we can delete the record: The…

  • Django Update Data

    Update Records To update records that are already in the database, we first have to get the record we want to update: x will now represent the member at index 4, which is “Stale Refsnes”, but to make sure, let us see if that is correct: This should give you this result: ‘Stale’ Now we can…

  • Django Insert Data

    Add Records The Members table created in the previous chapter is empty. We will use the Python interpreter (Python shell) to add some members to it. To open a Python shell, type this command: Now we are in the shell, the result should be something like this: At the bottom, after the three >>> write the following: Hit [enter]…

  • Django Models

    Django Models Up until now in this tutorial, output has been static data from Python or HTML templates. Now we will see how Django allows us to work with data, without having to change or upload files in the prosess. In Django, data is created in objects, called Models, and is actually tables in a…

  • Django Templates

    Templates In the Django Intro page, we learned that the result should be in HTML, and it should be created in a template, so let’s do that. Create a templates folder inside the members folder, and create a HTML file named myfirst.html. The file structure should be like this: Open the HTML file and insert the following: my_tennis_club/members/templates/myfirst.html: Modify the View Open…

  • Django URLs

    URLs Create a file named urls.py in the same folder as the views.py file, and type this code in it: my_tennis_club/members/urls.py: The urls.py file you just created is specific for the members application. We have to do some routing in the root directory my_tennis_club as well. This may seem complicated, but for now, just follow the instructions below. There is a file called urls.py on the my_tennis_club folder, open…