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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:32:02+00:00 2026-06-10T01:32:02+00:00

I’m new to Python, Google AppEngine and Jinja. If I’ve posted too much code

  • 0

I’m new to Python, Google AppEngine and Jinja. If I’ve posted too much code below, I am sorry. This is my first posted question to StackOverflow.

I’m building a blog (for a class) and I need to replace newline characters “\n” in the user’s post. The function that queries the database sends it’s results to a render() function.

All the code works perfectly until I add the line of code that is supposed to replace the “\n.”

I’ve done a variety of edits and I just can’t deduce what the AppEngine, or Jinja, or Python wants me to do to satisfy it.

My database class sets up the db_blog Kind with four types, including ‘post_content‘

class db_blog(db.Model):
    post_subject = db.StringProperty(required = True)
    post_content = db.TextProperty(required = True)
    post_created = db.DateTimeProperty(auto_now_add = True)
    post_last_modified = db.DateTimeProperty(auto_now_add = True)

The ‘Newpost’ class I want this to receive the ‘query_select‘ object from the Blog class below.

class Newpost(webapp2.RequestHandler):
    def write(self, *args, **kwds):
        self.response.out.write(*args, **kwds)

    def render_str(self, template, **params):
        t = jinja_env.get_template(template)
        return t.render(params)

    def render(self, template, **kwds):
        self._render_text = self.post_content.replace("\n", "<br />") ##<-- See here 
        self.write(self.render_str(template, **kwds))

The Blog class gets all user posts and sends them to ‘Newpost’ to be rendered.

class Blog(Newpost):
    def get(self):
        query_select = db.GqlQuery("SELECT * FROM db_blog ORDER BY post_created DESC")
        self.render('blog_posts.htm', query_select = query_select)

1. As shown above, the code will generate this error:

AttributeError: ‘Blog’ object has no attribute ‘post_content’

I take it that class Blog needs to inherit from db_blog, so (See #2)

2. If I add db_blog to the Blog class’ parameter list I get a new error:

AttributeError: ‘NoneType’ object has no attribute ‘replace’

I think the error is telling me that I’m passing an object that doesn’t exist, so I’m really confused. If I comment-out the line trying to replace the “\n”character, this code runs perfectly – so how can it NOT be passing the object? Or claim it’s == None?

More importantly, how can I get it to work!

Much thanks to you who read this far, and kingdoms of wealth to s/he that can get me going.

  • 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-10T01:32:04+00:00Added an answer on June 10, 2026 at 1:32 am

    The reason you are getting the attribute error is because the self in Newpost.get refers to the RequestHandler (Blog) and not to the post that you want. I suggest that, instead of defining the conversion in your view function, added it as a property on the model, e.g.

    class db_blog(db.Model):
    
        post_subject = db.StringProperty(required = True)
        post_content = db.TextProperty(required = True)
        post_created = db.DateTimeProperty(auto_now_add = True)
        post_last_modified = db.DateTimeProperty(auto_now_add = True)
    
        @property
        def escaped_content(self):
            # possibly want to escape HTML in your post_content first
            return self.post_content.replace("\n", "<br />")
    

    Then, you can just pass along query_select to your template (as you are currently doing now):

    {% for post in query_select %}
    {{ post.escaped_content | safe }}
    {% endfor %}
    

    You need to use safe above, because otherwise jinja will escape your <br />. Since I can’t see you template, I don’t know if this exactly fits what you are doing, but hopefully you get the point.

    To explain the three lines of jinja above:

    1. {% for post in query_select %} – just like a for loop, iterates over the posts, and each post should be a db_blog instance (from your query).
    2. post.escaped_content is exactly equivalent to calling the escaped_content attribute of your db_blog model in Python.
    3. {{ post.escaped_content | safe }} applies the safe filter to the string produced by escaped content (without safe, jinja would convert <br /> to &lt;br /&gt; (which would literally display <br /> on the page).
    4. {% endfor %} ends the for loop.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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.