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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:12:27+00:00 2026-05-18T09:12:27+00:00

I am using AppEngine with the webapp framework (python). In my script I am

  • 0

I am using AppEngine with the webapp framework (python). In my script I am generating javascript code dynamically with Django, for example:

python controller file

template_values = {
    'page': '1',               
}

path = os.path.join(os.path.dirname(__file__), "../views/index.html")
self.response.out.write(template.render(path, template_values))

index.html file

<html>
<head>
...
<script>
{% if page %}
   alert("test");
{% endif %}
</script>
</head>
<body>

...
</body>
</html>

Now, instead of using inline <script> tags I would like to use the <link> tags with a reference to a JS file containing the script. However, I can’t quite understand I can do that using the templates engine. If I include a JS file (dynamically) it would somehow have to know the value of “page”, but “page” is known in the scope of index.html only.

Any ideas?

Thanks,

Joel

  • 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-18T09:12:28+00:00Added an answer on May 18, 2026 at 9:12 am

    If you want dynamically generate your javascript code in your html,
    you can write the code inside python code

    page = 0
    template_values = {
        'js_code': 'alert("test:'+str(page)+'")',               
    }
    path = os.path.join(os.path.dirname(__file__), "../views/index.html")
    self.response.out.write(template.render(path, template_values))
    

    in index.html

    <script>
    {{js_code}}
    </script>
    

    If you want to generate a js file dynamically, you can try to pretend there is a js file,
    and generate its content.

    class JSHandler(BaseHandler):
        def get(self):
            page= str(self.request.get("page"))
            js_code ='alert("page:'+page+'");'
            self.response.out.write(js_code)
    
    
    def main():
     application = webapp.WSGIApplication([
      ('/code.js', JSHandler),
        ], debug=True)
     wsgiref.handlers.CGIHandler().run(application)
    

    Then you can write this code in your html

    <script type="text/javascript" src="/code.js?page={{page}}">></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the appengine webapp framework ( link ). Is it possible to add
I am using python and webapp framework in app engine for backend and flex
I am using a perl script to POST to Google Appengine application. I post
I'm a python newbie and starting out with using the Bottle web framework on
If I write a python script using only python standard libraries, using Python 2.6
I am considering using AppEngine for deploying a webapp which I am developing. As
I'm using python, django and google app engine and I'm getting the error below.
I am using google's appengine api from google.appengine.api import urlfetch to fetch a webpage.
I'm using Google App Engine and Django templates. I have a table that I
As the title suggests, I'm using Google App Engine and Django. I have quite

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.