Click here to Skip to main content
15,743,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a learning portal, in which students can learn on various books. Each book will have various chapters / topics.

Each topic is having a unique slug, as reflected the below mentioned model, which we want to render / show on an HTML page, upon clicking on it.

I want to show the contents of the topic on a separate HTML page, when somebody click on that particular topic. I have written the below mentioned code, however, failed to populate the data on the HTML.

My Django model, and is as under.

My Django model is as follows:

class book_explination(models.Model):
       title = models.CharField  (max_length = 255)
       slug = models.SlugField(max_length= 250, null = True, blank = True, unique= True)
       lesson_no = models.CharField  (max_length = 255)
       book_text = models.TextField  (blank=False, null=False)
my view is as follows:

def topic_detail(request, url):
    topic_detail = book_explination.objects.get(slug = url)
    return render(request, 'blog/topic_detail.html', {'topic_detail':topic_detail})
The HTML rendering page is as follows:

{% block content %}
  <div class="container">
    <p> {{lesson_no | safe}} </p>
    <p> {{book_text | safe}} </p>
    <p> {{book_text_explination | safe}} </p>
{% endblock %}    

  {% for c in topic_detail %}
    <li>{{ c.lesson_no }}</li>
    <li>{{ c.lesson_no }}</li>
    <li>{{ c.lesson_no }}</li>
  {% endfor %}
I would be very thankful for your help. Thanks

What I have tried:

I want to show topic wise data on the html page, by django variable, however failed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900