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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:58:00+00:00 2026-05-31T06:58:00+00:00

How can I use modules in views? For example I’m trying to use the

  • 0

How can I use modules in views?
For example I’m trying to use the markdown module, so I import it into my controller:

from gluon.contrib.markdown.markdown2 import markdown

and I use response.render

return response.render('default/main.html', locals())

but when I try to access it in a view,

{{=markdown(post.message)}}

I get an error saying that it is not defined:

<type 'exceptions.NameError'> name 'markdown' is not defined

How can I pass module to views? Is there an alternative to the locals() function to get it done?

On a side note, I can access db and session from my views, is this because they are imported in my models?

Web2Py Version 1.99.7 (2012-03-04 22:12:08) stable

UPDATE: Importing it in my model db.py seems to fix it. Is there a better way to do this?

  • 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-31T06:58:02+00:00Added an answer on May 31, 2026 at 6:58 am

    Just for record.

    It is not a good idea to use locals()

    instead of passing locals to response.render, it is better to create a dictionary with the keys you want to be available for the view to be rendered.

    You can also include a reference to markdown on that dictionary

    from gluon.contrib.markdown.markdown2 import markdown
    mydict = dict(markdown=markdown, anotherkey=anothervalue)
    return response.render("path/to/view", mydict)
    

    Dont try to extend locals() in to mydict, you will run in to problems if you try this.

    Also you can just use the default web2py behavior

    from gluon.contrib.markdown.markdown2 import markdown
    response.view = "path/to/view"
    return dict(markdown=markdown, anotherkey=anothervalue)
    

    another option for you is to import markdown in a model file.

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

Sidebar

Related Questions

I'm trying to find a markdown interpreter class/module that I can use in a
I'm trying to use modules in the ZF 1.8 project but can't get working
I've seen people use monkey-patching to set options on a module, for example: import
In python we can use multiprocessing modules. If there is a similar library in
Can anyone recommend an SVN client for use in Excel with VBA (code modules
How can I install X-Sendfile apache module so that MAMP can use it? I
The Term::Size-module jumbles up the encoding. How can I fix this? #!/usr/bin/env perl use
I'm developing a Django app, and I'm trying to use Python's logging module for
You can use more than one css class in an HTML tag in current
You can use a standard dot notation or a method call in Objective-C to

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.