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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:23:28+00:00 2026-05-31T05:23:28+00:00

I sometimes need to use partial views in Web2Py , but I need to

  • 0

I sometimes need to use partial views in Web2Py, but I need to pass some specific variables to them. In Django it would look like this:

{% include "image.html" with caption="Me" source="http://example.com/img.png" %}

In case of Web2Py I can do something like:

{{ include "image.html" }}

but there is not even a single mention about passing variables to partial views within the documentation (or I am missing something pretty obvious).

The use case for this is decreasing complexity of the views (and implementing DRY rule) and displaying some complex content within a loop (eg. images, complex containers etc.).

I do not want to use my own tags/functions instead – I need something quick and simple, just to include partial view with specific variables. Similarly as it could be done in Django or many other web frameworks. Is it even possible, or due to Web2Py’s architecture it is rather impossible / laborous?

Please tell me if this is possible in web2py or if I should rather create my own tag to use it within views (if so, what is the easiest/simplest way to do it?).

Thanks.

  • 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-31T05:23:29+00:00Added an answer on May 31, 2026 at 5:23 am

    Interrobang’s answer is correct — variables returned by the controller will be available even in included (as well as extended) views. So, you can do:

    In mycontroller.py:

    def myfunc():
        return dict(caption='Me', source='http://example.com/img.png')
    

    and then in /views/mycontroller/myfunc.html:

    {{include 'image.html'}}
    

    In that case, caption and source will be available in the image.html view. Instead of returning caption and source from the controller, another option is just to define them in the view before the include directive:

    {{caption = 'Me'
      source = 'http://example.com/img.png'}}
    {{include 'image.html'}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Use MVC and sometimes need to pass the ViewBag.Message from Controller to view,
I need to use HTML comments to store specific data, but I don't want
I am developing PhoneGap webapp where I use some javascript, and sometimes I need
I sometimes need to use Visual Studio when I have limited screen real estate
I'm writing a script for IRC and sometimes I might need to use a
I use huge data files, sometimes I only need to know the number of
I sometimes need to look for information for a special portion of code. When
I sometimes need to debug JS in other browsers, and it would be really
Sometimes I need to quickly extract some arbitrary data from XML files to put
Sometimes I need to use several disposable objects within a function. Most common case

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.