2012-02-21, 19:04
hagur Wrote:Hi guys,
Just discovered this amazing thing and set it up, worked like a charm. I'm keen on developing my own modules, but I'm not sure how it's done.
Let's say my module is called mymodule.
This is what I've done so far:
- Added my new module to maraschino/modules.py
- Created mymodule.html in maraschino/templates
- Created mymodule.py in maraschino/modules
- Edited maraschino.py and added: "from modules.mymodule import *"
Now I can enter the config mode and select mymodule and add it to the page. Works fine. The mymodule.html template is rendered out, works fine.
When I edit mymodule.py I can see that the dev server detects the change, restarts and a mymodule.pyc file gets created, so my module is being picked up and compiled by python, apparently.
BUT ... It's not like any code in mymodule.py is actually being run. I can type whatever crap I like in there, and still get no error messages.
I'm also confused about the "entry point" in mymodule.py, does it need to have a constructor? Looking at some of the other modules, I see that there's a function with the same name as the module, so I typed that in, like so:
def xhr_mymodule():
print "ASDF"
return render_template('mymodule.html',
caption = "HELLO WORLD!"
)
but this never seems to run. Nothing gets printed out and the render_template method seems to do nothing.
In fact, I can remove mymodule.py completely and remove the "from modules.mymodule import *" line from maraschino.py file and my module still "works", that is, it gets rendered out. If I remove mymodule.html from the template folder then I finally get an exception from Flask, saying it cannot find a template called mymodule.html.
So I guess the real question is, what do I have to do to "link" mymodule.html to mymodule.py so I can call render_template and pass it some data?
Hope someone can help ... I've looked through most of the modules that ship with Maraschino and I cannot see what I'm doing wrong (or not doing).
Dude why are you hi-jacking this thread with unrelated issue. You should open a new thread in the developer area