Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6599671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:31:18+00:00 2026-05-25T18:31:18+00:00

I am trying to implement an ajax view to create an object and then

  • 0

I am trying to implement an ajax view to create an object and then return it and insert it into the template. It is almost working except I cannot seem to get render_to_string() to work to render the html to insert. The object is being created and html is being returned and inserted into the template however the variables are not included in the html. My view is below.

def tr_create_xhr(request, person, slug):
if request.method == "POST":
    form = TopicResourceForm(request.POST)
    if form.is_valid():
        try:
            r = Resource.objects.get(url=form.cleaned_data['resource'])
        except Resource.DoesNotExist:
            r = Resource.objects.create(url=form.cleaned_data['resource'], rtype=form.cleaned_data['rtype'])
            r.save()
    obj = form.save(commit=False)
    obj.resource = r
    try:
        topic = Topic.objects.get(person__user=request.user, slug__iexact=slug)
    except Topic.DoesNotExist:
        return Http404
    obj.topic = topic        
    objs = obj.save()
    html = render_to_string('includes/tr_inc.html',{"r":objs, "topic":topic})
    res = {'html':html}
    if request.is_ajax():
        return HttpResponse(simplejson.dumps(res), mimetype="application/json")
    else:
        return HttpResponseRedirect("../..")
return Http404

This is the template “includes/tr_inc.html”:

{% load markup %}
{% load people_tags %}



    <li>

        <h5>{{ r.title }}</h5>
        <p><a class="tru" href={{ r.resource.url }}>{{ r.resource.url|sliceit:70 }}</a></p>
        <span class="oc"><p>Added {{ r.added }}{% if r.rtype %} |<a href={% url resource_type_detail r.rtype.slug %}>{{ r.rtype }}</a>{% endif %}

| <a href="/topics/user/{{ r.topic.person.user }}/{{ r.topic.slug }}/topic-resource/delete/{{ r.id }}/">Delete</a> <a href="/topics/user/{{ r.topic.person.user }}/{{ r.topic.slug }}/topic-resource/edit/{{ r.id }}/">Edit</a>

        {{ r.note|markdown }}</span>
    </li>

The html string that is returned is the template without any variables inserted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:31:19+00:00Added an answer on May 25, 2026 at 6:31 pm

    Model method ‘save’ doesn’t return an object. So you ‘objs’ variable is empty. You should write

    html = render_to_string('includes/tr_inc.html',{"r":obj, "topic":topic})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a mobile view of our site. I'm trying to implement JQuery
I am trying to implement AJAX in my Google App Engine application, and so
I am trying to implement ajax back/forward button support and therefore writing variables after
I am trying to implement a simple request to Wikipedia's API using AJAX (XMLHttpRequest).
I am trying to implement ajax in jsp(avoid form submit) using struts2. I used
I'm trying to implement jQuery tabs to replace AJAX tab container. I've followed the
Yesterday I was trying to implement a Listener for a SelectManyListbox using Ajax in
Details: I'm basically trying to implement the functionality of the example here ( http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultvb.aspx
so i'm currently trying to implement a currency conversion script using Jquery, curl, ajax
I'm trying to implement an AJAXfied Wicket list view. On my research I stumbled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.