You are not logged in.

Change Language:

Profile for Trikks

Name Trikks
Email Address n/a
Posts2
  • 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
  • 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 model
        class Page(models.Model):
            def index(self):
        	  ex = 'foo string'
        	  return ex
    


    The view
        def 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 &lt;unbound method Page.index&gt;

    ...


    The funny thing is that if I skip the functions and so on and creates the model like this
        class 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


Powered by Sphene Community Tools