| Name | Trikks |
|---|---|
| Email Address | n/a |
| Posts | 2 |
-
- 2010-06-27 10:10:06
- Re: Returning static values from methods in Django
- Board » Django » Models
-
Hi, well hmm, actually im just trying to pass a static value from the model to the view. But I've figured out thats not how you do it in Django. In the actual case I have no database what so ever and do not wish to store anything. Thus it seems as if i have to put my logic in the view, or in a separate py-file and import it!
/ Trikks
-
- 2010-06-27 08:18:25
- Returning static values from methods in Django
- Board » Django » Models
-
Hi!
So, time for a newbie question but so utterly important since the documentation seems to have missed this very very basic example.
All I'm trying to do is to return a value from a model to a view in Django. Here is some code.
The modelclass Page(models.Model): def index(self): ex = 'foo string' return ex
The viewdef index(request): start = Page.objects.all().index #start = Page.index # <- this one bugs to... return render_to_response('index.html', {'page_content': start})
And, nothing gets rendered. I get this error message with <unbound method Page.index>
...
The funny thing is that if I skip the functions and so on and creates the model like thisclass Page(models.Model): ex = 'goo string'
And call it with
start = Page.ex
Everything renders out fine.
Any pointer or working example would be much appreciated!
Thanks


