is this my correct results.html and detail.html code?i am only a beginer, please check

28 views
Skip to first unread message

Avitab Ayan Sarmah

unread,
Jun 6, 2018, 1:01:05 PM6/6/18
to Django users
results.html:

<h1>{{ question.question_text }}</h1>

<ul>
{% for choice in question.choice_set.all %}
  <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{
choice.votes|pluralize }}</li>
{% endfor %}
</ul>

<a href="{% url 'polls:detail' question.id %}">vote again?</a>


detail.html:

<h1>{{ question.question_text }}</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
{% for choice in question.choice_set.all %}
  <input type="radio" name="choice" id="choice{{ forloop.counter }}"
value="{{ choice.id }}" />
  <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}
</label><br />
{% endfor %}
<input type="submit" value="vote" />
</form>

Anthony Flury

unread,
Jun 6, 2018, 5:15:15 PM6/6/18
to django...@googlegroups.com
I can't see anything necessarily wrong in terms of most browsers but it
isn't strictly compliant with the HTML standards.

To be strict HTML, your html files should be including *html* and *body*
tags as a minimum.

The *html* tag starts and end the html file - in theory browsers are
entitled to ignore content sent to it that doesn't start with *html* tags;

The *body* tag is used to wrap the content of the data which needs to be
displayed by the browser.

So in theory - a better results.html would be

<html>
<body>
<h1>{{ question.question_text }}</h1>

<ul>
{% for choice in question.choice_set.all %}
     <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{
choice.votes|pluralize }}</li>
{% endfor %}
</ul>

<a href="{% url 'polls:detail' question.id %}">vote again?</a>
</body>
</html>

At the end of the day though - it really does depend on what correct
means to you.

1. Do you want to make sure that your pages are closer to strict HTML -
which means that in complex pages, the browser will stand a better
chance of displaying what you want

or

2. Do you simply want to ensure that the browser you use displays what
you expect - if so - strict HTML isn't necessary; so long as it works
for you.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6b6eb6ac-7152-474e-88eb-2da9eb473d3f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6b6eb6ac-7152-474e-88eb-2da9eb473d3f%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

C. Kirby

unread,
Jun 7, 2018, 9:48:25 AM6/7/18
to Django users
Everything that TonyF said, but also - your choice.votes|pluralize tag will not work - tags need to be all on online from open to closing braces
Reply all
Reply to author
Forward
0 new messages