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

  • Home
  • SEARCH
  • 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 358729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:19:37+00:00 2026-05-12T12:19:37+00:00

I’m using google appengine (python, of course :) ) and I’d like to do

  • 0

I’m using google appengine (python, of course 🙂 ) and I’d like to do a string.replace on a string from the template file.

{% for item in items %}
  <p>{{ item.code.replace( '_', ' ' ) }}</p>
{% endfor %}

But that isn’t working. So we cannot execute anything other than basic checks in the app engine templates. Is that Correct ?


Another related problem is I’m trying to shorten a string and make it available to the template.

Each furniture object has a name and a longer description field. In this view I’m rendering, I want only the first 50 characters of the description field.

So I tried something like

items = db.GqlQuery( 'select * from furniture' )

# edit:  if you change the above line to
# items = db.GqlQuery( 'select * from furniture' ).fetch( 1000 )
# the .fetch() command makes the addition of dynamic properties work!

for item in items :
  item.shortdescr = item.description[ 0:50 ]

# pass data off to template for rendering
self.response.out.write(
  template.render( 'furnitureAll.html', { 'items' : items } )
)

Template goes


{% for item in items %}
  <p>{{ item.name }}</p>
  <p>{{ item.shortdescr }}</p>
  <!-- items.shortdescr does not exist here,
  probably because I did not .put() it previously. -->
{% endfor %}

Since that didn’t work, I tried changing the Gql Query to shorten the string instead. But I’m quickly realizing Gql isn’t like SQL. I’m trying to write queries like

select name,LEFT( description, 50 ) from furniture

With little success

  • 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-12T12:19:38+00:00Added an answer on May 12, 2026 at 12:19 pm

    I have little experience with Google AppEngine, but my understanding is that it is very closely related to Django. Your templates do not actually contain Python code, even if some of the structures you use in them look like it.

    Both of your questions should be solved using template filters. If it was Django, I would use something like this for your second question:

    {{ item.description|truncatewords:10 }}
    

    For your first question (string replace), there may be no built-in filter you can use for that. You will need to write your own. Something like this;

    from google.appengine.ext.webapp.template import create_template_register
    
    register = create_template_register()
    
    @register.filter
    def replace_underscores(strng):
        return strng.replace('_', ' ')
    

    Then, in your template, you can do this:

    {{ item.code|replace_underscores }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 225k
  • Answers 226k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Most implementations of std::sort use quicksort, (or usually a hybrid… May 13, 2026 at 1:05 am
  • Editorial Team
    Editorial Team added an answer That sounds like a DevExpress Addin http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/ it has many… May 13, 2026 at 1:05 am
  • Editorial Team
    Editorial Team added an answer Don't get rid of the comments. Comments are good. They… May 13, 2026 at 1:05 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.