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 8699473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:57:19+00:00 2026-06-13T01:57:19+00:00

I’m writing a facebook-like posting system where a user can type in a text

  • 0

I’m writing a facebook-like posting system where a user can type in a text comment and have it immediately appear on the page in a properly styled and formatted box, as simultaneously the text is ajax’d to the backend to be stored. A comment is fundamentally a HTML5 , but there’s a fairly complicated level of structure to it, so the actual text should appear in a div within a div within a div ultimately within the article. I’m doing this DOM manipulation with jquery.

When the page is generated, the backend needs to iterate over every comment, and insert the comment text (as well as metadata like name of poster, timestamp, etc.) into the appropriate places in a django template.

This presents a conceptual problem – I’m now duplicating a fairly complicated set of nested html tags with appropriate class and id names in two places in my code: the js file with the jquery to add a new comment, and the backend templating engine to generate the initial page html. This is already a problem for me because I’m still in the process of designing exactly what needs to happen style-wise in a comment and having this complicated bundle of HTML in two places in my code has already tripped me up.

What is the best practice for dealing with this sort of HTML duplication? I can’t remove the jquery, because I need that to handle the dynamic addition of comments. At the same time, it seems wasteful to give up the power of django’s templating engine to build the HTML structure I need once and fill in the details on a per-comment basis – plus I don’t want to always render a blank page and build up possibly very many comments dynamically with jquery DOM manipulation every time the user loads a page. Is there something I’m not thinking of that would solve this problem?

  • 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-06-13T01:57:20+00:00Added an answer on June 13, 2026 at 1:57 am

    Just get your Ajax handling views to return rendered HTML fragments, using the templates, rather than JSON, and the jQuery simply inserts them in the right place, rather than building them up from raw data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.