72👍
You are returning a tuple here:
elif retailer_pk:
return (request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Did you forget to add render
there perhaps:
elif retailer_pk:
return render(request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
7👍
There is an extra comma "," at the end of return
function in views.py
return render(request, 'index.html',{}), #incorrect
return render(request, 'index.html',{}) #correct
- [Django]-How to create table during Django tests with managed = False
- [Django]-How can I get the object count for a model in Django's templates?
- [Django]-Why don't my south migrations work?
7👍
Always make sure you have render after ‘return’, in your views functions
In my case I had not added the
return render(request, app_name/index.html
It took me a lot of time to find this bug and not even one of the answers on stack overflow mentioned it, that’s why I posted it here.
{IMAGE} check the index and register functions and the error indicated below them.
- [Django]-Running django tests with sqlite
- [Django]-How to get unique users across multiple Django sites powered by the "sites" framework?
- [Django]-What's the correct way to set up Django translation?
1👍
Even taking the commas of the views is as simple of a solution
as-in
this
def home(request):
return render(request, 'index.html')
def hire(request):
return render(request, 'hire.html')
def handler400(request, exception):
return render(request, '400.html', locals())
def handler403(request, exception):
return render(request, '403.html', locals())
def handler404(request, exception):
return render(request, '404.html', locals())
def handler500(request, exception):
return render(request, '500.html', locals())
Rather than
this
def home(request):
return render(request, 'index.html'),
def hire(request):
return render(request, 'hire.html'),
def handler400(request, exception):
return render(request, '400.html', locals()),
def handler403(request, exception):
return render(request, '403.html', locals()),
def handler404(request, exception):
return render(request, '404.html', locals()),
def handler500(request, exception):
return render(request, '500.html', locals())
- [Django]-Django DetailView – how to use 'request' in get_context_data
- [Django]-Can I call a view from within another view?
- [Django]-Django Templates – Changing context for an 'include' template
1👍
you forgot to add render
after return
so you just need to add render
after return
The part you wrote(look at the last elif):
elif retailer_pk:
return (request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
but it would be :
elif retailer_pk:
return render(request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
- [Django]-DateTimeField doesn't show in admin system
- [Django]-How can I PUT/POST JSON data to a ListSerializer?
- [Django]-Model not showing up in django admin
0👍
Had a similar problem and discovered that the error was from the spacing between the function name and the request
I did this :
def greet (request, name):
return render(request, "hello/greet.html", {
"name": name. Capitalize()
})
instead of this:
def greet(request, name):
return render(request, "hello/greet.html", {
"name": name. Capitalize()
})
The space between 'greet' and '(request, name)' was responsible for the error
- [Django]-How To Run Arbitrary Code After Django is "Fully Loaded"
- [Django]-Elastic Beanstalk could not find any platforms
- [Django]-How can I make a Django form field contain only alphanumeric characters
0👍
simply the problem is, there is no extra comma after the bracket
before
def home(request):
return render(request,'home.html',{}), //error bcz of extra comma
after
def home(request):
return render(request,'home.html',{}) //no error
- [Django]-How to implement breadcrumbs in a Django template?
- [Django]-Django, jQuery, and autocomplete
- [Django]-Check for pending Django migrations
-2👍
This bug took me so much time to find, and I couldn’t find the answer here. Just something similar, so I decided to drop this exact one here:
Incorrect:
return render(request, 'templates folder directory', {'team': team}, {'form': form})
Correct:
return render(request, 'templates folder directory', {'team': team, 'form': form })
- [Django]-Django formset unit test
- [Django]-How to stop autopep8 not installed messages in Code
- [Django]-Can you perform multi-threaded tasks within Django?