1👍
You can only have one context dictionary, but a dictionary can have as many key/values as you want.
def home(request):
context = {'title': 'HOME','post': posts}
return render(request, 'blog/home.html',context)
1👍
What about this one?
{
'title': 'HOME',
'post': posts
}
This way, both variables are part of the same object.
It’s crucial to put both values to the same data structure, because in your code, post
was a fourth parameter, which is reserved for a different functionality.
- [Django]-Rest Framework Image Validation
- [Django]-Django/Travis CI – configuring a .travis YAML file to first start a localhost server, then run my tests without hanging?
- [Django]-Django: object needs to have a value for field "…" before this many-to-many relationship can be used
- [Django]-How to check if a checkbox is checked in django template
- [Django]-Django models.ForeignKey filter
1👍
You can only pass one dictionary as the context for the page.
def home(request):
context = {'title': 'HOME',
'post': posts }
return render(request, 'blog/home.html', context)
- [Django]-How do I properly configure my app to use the Django phonenumber field module?
- [Django]-Invalid embedded document instance provided to an EmbeddedDocumentField
- [Django]-How to get penultimate item from QuerySet in Django?
- [Django]-How to remove all many to many objects in Django
1👍
Django’s render
function takes only one positional argument for context. that’s why your first dictionary is working and the second one is chopped off as Django take fourth positional argument as content_type
render(request, template_name, context=None, content_type=None, status=None, using=None)
ref : https://docs.djangoproject.com/en/2.2/topics/http/shortcuts/
So you should pass only one object of dictionary with all your desired data. it can have nested object.
def home(request):
context_data = {'title': 'Home',
'post': posts }
return render(request, 'blog/home.html', context_data)
- [Django]-Getting error "SuspiciousFileOperation" after Django Version Update Django: 3.1.9 from Django: 3.1.8
- [Django]-AttributeError: 'DatabaseWrapper' object has no attribute 'set_schema_to_public' (tenat_schemas)
- [Django]-AttributeError at /accounts/login/ 'dict' object has no attribute 'status_code'
- [Django]-How to call multiple views on one url in pinax