Reputation: 15
I am trying to pass the following argument to a render to response syntax in django but i keep getting the following error:
render_to_string() got multiple values for argument 'context_instance'
Tried different solutions but still not getting it right. Any help?
views.py:
@login_required
def articles(request, everyone=True):
events = post.objects.filter()
if request.user.is_authenticated():
my_events = events.filter(user=request.user)
events = events.exclude(user=request.user)
following = request.user.following_set.all().values_list('to_user',
flat=True)
else:
my_events = post.objects.none()
following = None
if not everyone:
events = events.filter(user__in=following)
args = {}
args.update(csrf(request))
args ['posts'] = post.objects.filter(user = request.user)
args ['full_name'] = User.objects.get(username = request.user.username)
args ['form'] = PostForm()
args ['forms'] = CommentForm()
args ['profile_picture'] = request.user.profile.profile_picture
context = {
'events': events,
'my_events': my_events,
'following': following,
}
return render_to_response('articles.html', args, context,
context_instance = RequestContext(request))
Is there anything am doing wrong?
Upvotes: 0
Views: 2750
Reputation: 893
Here is the render_to_string from the django source django.template.engine :
def render_to_string(self, template_name, dictionary=None, context_instance=None,
dirs=_dirs_undefined):
It gets called with (*args,**kwargs)
passed from render_to_response()
It is clear that your context
argument conflicts with keyword argument assigned by you which is context_instance
. You should only send one of those. Maybe you should put the data from context
inside your args
dictionary?
By the way you can look at the docs here: https://docs.djangoproject.com/en/dev/ref/templates/api/#the-render-to-string-shortcut and here: https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response
to see the list of arguments each of this functions accepts.
Upvotes: 1