6👍
Yes, the error is quite clear: you have two blocks named “content”.
To be honest I can’t understand what you’re doing, as the second block seems to be an exact duplicate of the first. You can’t have two extends
tags either.
1👍
You can do the things you want to in the back-end, ie:- Python.
You can for example do something like:-
# views.py::
if something is True(any condition for that matter)
msg = "something"
else:
msg = "Something else"
# template, it is here -- index.html::
{% block title %}{{msg}}{% endblock title %}
- AttributeError : 'NoneType' object has no attribute '_meta'
- Blank label_suffix across entire Django project
- Django conditional Subquery aggregate
0👍
If there is any variable that you want to render it more than once.
Just pass as input while rendering the file.
Like This:
from django.shortcuts import render
def products_list(request):
return render(request, "products/list.html",
{
"title":"Products List"
})
Inside the HTML File:
<html>
<head>
<title>{{ title }} | My Website</title>
</head>
<body>
<h1>{{ title }}:</h1>
</body>
This will be rendered like this:
<html>
<head>
<title>Products List | My Website</title>
</head>
<body>
<h1>Products List:</h1>
</body>
0👍
I think sometimes the error code maybe a little straight forward, "I think". Anyway I solved this problem by deleting the extra line tag(s), in this case the {% block content %}
line tag.
- Upload direct to S3 or via EC2?
- How to design shopping basket using session?
- Django 1.2 Equivalent of QuerySet.query.as_sql()
- Cannot list all of my fields in list_editable without causing errors
- Django RuntimeError at /admin/users/user/1/change/, Single thread executor already being used, would deadlock
0👍
In my case, it was solved by changing the name of the block content.
My scenario with this error was:
Some pages of my site are open to the public.
Some pages of my site are free for site users to see.
Because my user registration was entered in a user authentication step, I was checking the site. If it is anonymous, it must register first, so I had two options to check.
The first case (if anonymous) Ligen pages, home, rules and ..
Redomination mode (if the site user) pages, profiles and apps
I changed the content blocks to solve the name.
In the base.html file:
This base forum:
{% block content1%}
user.is_anonymous
{% endblock content1%}
block% block content2%}
is_authenticated
end% endblock content2%}