Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 June 15, 2010 05:55:59

Joel K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


I am working on a simple site right now and the views are pretty easy.
Usually just iterate a loop of objects. But, I am trying to figure out
how a website with all different kinds of data, including a sign in
form, is setup in django. Is that all in one big view? Or, is there
some way to combine them?

Any insight would be helpful, thank you.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 15, 2010 10:01:39

Venkatraman S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


On Tue, Jun 15, 2010 at 10:25 AM, Joel Klabo <joelkl...@gmail.com> wrote:

> I am working on a simple site right now and the views are pretty easy.
> Usually just iterate a loop of objects. But, I am trying to figure out
> how a website with all different kinds of data, including a sign in
> form, is setup in django. Is that all in one big view? Or, is there
> some way to combine them?
>
> Any insight would be helpful, thank you.
>
>
You can define a module which does some functions and call them from
views.py
If your present site is simple, probably you dont even a views.py and can
just run it from urls.py(generic views)

-V-http://twitter.com/venkasub--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 15, 2010 11:24:42

Sithembewena L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


@Venkatraman, wouldn't urls.py need views.py to map to?

On Tue, Jun 15, 2010 at 11:01 AM, Venkatraman S <venka...@gmail.com> wrote:

>
> On Tue, Jun 15, 2010 at 10:25 AM, Joel Klabo <joelkl...@gmail.com> wrote:
>
>> I am working on a simple site right now and the views are pretty easy.
>> Usually just iterate a loop of objects. But, I am trying to figure out
>> how a website with all different kinds of data, including a sign in
>> form, is setup in django. Is that all in one big view? Or, is there
>> some way to combine them?
>>
>> Any insight would be helpful, thank you.
>>
>>
> You can define a module which does some functions and call them from
> views.py
> If your present site is simple, probably you dont even a views.py and can
> just run it from urls.py(generic views)
>
> -V-
>http://twitter.com/venkasub>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>



--
Regards,
Sithembewena Lloyd Dubehttp://www.lloyddube.com--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 15, 2010 11:33:34

Ian M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


I have a site that has quite a few Django based pages plus login etc.
and I certainly had to structure the code over multiple modules. I
suggest that you do both a top-down and a bottom-up design (actually,
iterate between these).

Start with a top-down view which is the urls - list those and plan for
a single view method for each url. I then started with a single
view.py source file and added each view method to it. After a while.
this single views.py grew too large to be easily manageable so I split
it. There are two ways to split it.

Firstly, having one file called views.py is only a convention. it is
a useful convention but it can be broken so for one of my apps, I
split the view methods into four separate source files and referred to
those from urls.py. In my case, I had messages.py, groups.py etc.

Secondly, as one of the other posters said, if you have commonly used
utility functions then they can be pulled out into separate modules.

Once you realise that the views.py is only a convention then it just
becomes a question of structuring a large Python app.

Hope this helps,
Ian McDowall

On Jun 15, 5:55 am, Joel Klabo <joelkl...@gmail.com> wrote:
> I am working on a simple site right now and the views are pretty easy.
> Usually just iterate a loop of objects. But, I am trying to figure out
> how a website with all different kinds of data, including a sign in
> form, is setup in django. Is that all in one big view? Or, is there
> some way to combine them?
>
> Any insight would be helpful, thank you.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 June 15, 2010 12:32:12

Venkatraman S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


On Tue, Jun 15, 2010 at 3:54 PM, Sithembewena Lloyd Dube
<zebr...@gmail.com>wrote:

> @Venkatraman, wouldn't urls.py need views.py to map to?
>


Depends on how you have structured your app and what is the functionality of
your app.
Refer tohttp://www.djangobook.com/en/2.0/chapter11/how you can simply
avoid views.py and run your app from views.py.

If i am right, django-basic-apps has this blog module which doesnt have
views.py and the urls.py is pretty nifty to take care of ALL the processing.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 June 15, 2010 12:48:31

Sithembewena L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


Interesting, thanks Venkatraman. Just finishing up the tutorial at this
point. Will look at that page.

On Tue, Jun 15, 2010 at 1:32 PM, Venkatraman S <venka...@gmail.com> wrote:

>
> On Tue, Jun 15, 2010 at 3:54 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> @Venkatraman, wouldn't urls.py need views.py to map to?
>>
>
>
> Depends on how you have structured your app and what is the functionality
> of your app.
> Refer tohttp://www.djangobook.com/en/2.0/chapter11/how you can simply
> avoid views.py and run your app from views.py.
>
> If i am right, django-basic-apps has this blog module which doesnt have
> views.py and the urls.py is pretty nifty to take care of ALL the processing.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>



--
Regards,
Sithembewena Lloyd Dubehttp://www.lloyddube.com--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 June 15, 2010 12:53:20

Gerard J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


As your site gets bigger, as mine does, you can choose to split up
your views over multiple .py files based on e.g. functional sections.
I recently created a file named views_admin.py. Following the Django
docs, I also named files based on contents. So a mydecorators.py, etc
( the my.. prefix is to make sure you don't have name clashes).

Hope it helps.

Regards,

Gerard.

On Jun 15, 6:55 am, Joel Klabo <joelkl...@gmail.com> wrote:
> I am working on a simple site right now and the views are pretty easy.
> Usually just iterate a loop of objects. But, I am trying to figure out
> how a website with all different kinds of data, including a sign in
> form, is setup in django. Is that all in one big view? Or, is there
> some way to combine them?
>
> Any insight would be helpful, thank you.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 June 15, 2010 16:13:03

P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


On 15 Jun., 06:55, Joel Klabo <joelkl...@gmail.com> wrote:
> I am working on a simple site right now and the views are pretty easy.
> Usually just iterate a loop of objects. But, I am trying to figure out
> how a website with all different kinds of data, including a sign in
> form, is setup in django. Is that all in one big view? Or, is there
> some way to combine them?
>
> Any insight would be helpful, thank you.

Hi Joel,

very good question, I take it you want to know how "composition" is
done at the "page level" without dragging all the logic into one view.
In django you can generate recurring elements with template tags, for
adding variables to the request or generate markup directly.

say you want a list of users that joined your site recently:

class RecentUsersNode(template.Node):
def __init__(self, limit):
try: self.limit = int(limit)
except ValueError: self.limit = 10

def render(self, context):
profiles = UserProfile.objects.order_by('user__date_joined')

context = profiles
return ''

@register.tag
def recent_users(parser, token):
args = token.split_contents()
if len(args) <= 1:
return RecentUsersNode(10)

num = args
if(num == num and num in ('"', "'")):
num = num # strip quotes
return RecentUsersNode(num)



{% recent_users %} will add a list of UserProfile objects to your
request and you can use it like:

{% for profile in recent_users %}
<img src="{{ profile.photo.url }}" alt="{{ profile.desc }}" />
{% endfor %}


In the old days of web 1.0 there was a natural 1:1 mapping from the
page to a script/function which generates the content. With ajax it's
becoming more like a desktop app where you have many parts/widgets
with callbacks or events. If you want the page to display without JS,
you still have to generate the page with one request though...

cheers
Paul

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#9 June 15, 2010 17:17:51

Joel K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


Thanks, good info. So the template tag can do the DB query and all
that without going through a view function?

On Jun 15, 8:09 am, Paul <pkoe...@gmail.com> wrote:
> On 15 Jun., 06:55, Joel Klabo <joelkl...@gmail.com> wrote:
>
> > I am working on a simple site right now and the views are pretty easy.
> > Usually just iterate a loop of objects. But, I am trying to figure out
> > how a website with all different kinds of data, including a sign in
> > form, is setup in django. Is that all in one big view? Or, is there
> > some way to combine them?
>
> > Any insight would be helpful, thank you.
>
> Hi Joel,
>
> very good question, I take it you want to know how "composition" is
> done at the "page level" without dragging all the logic into one view.
> In django you can generate recurring elements with template tags, for
> adding variables to the request or generate markup directly.
>
> say you want a list of users that joined your site recently:
>
> class RecentUsersNode(template.Node):
>     def __init__(self, limit):
>         try: self.limit = int(limit)
>         except ValueError: self.limit = 10
>
>     def render(self, context):
>         profiles = UserProfile.objects.order_by('user__date_joined')
>
>         context = profiles
>         return ''
>
> @register.tag
> def recent_users(parser, token):
>     args = token.split_contents()
>     if len(args) <= 1:
>         return RecentUsersNode(10)
>
>     num = args
>     if(num == num and num in ('"', "'")):
>         num = num # strip quotes
>     return RecentUsersNode(num)
>
> {% recent_users %} will add a list of UserProfile objects to your
> request and you can use it like:
>
> {% for profile in recent_users %}
>   <img src="{{ profile.photo.url }}" alt="{{ profile.desc }}" />
> {% endfor %}
>
> In the old days of web 1.0 there was a natural 1:1 mapping from the
> page to a script/function which generates the content. With ajax it's
> becoming more like a desktop app where you have many parts/widgets
> with callbacks or events. If you want the page to display without JS,
> you still have to generate the page with one request though...
>
> cheers
>  Paul

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#10 June 15, 2010 17:22:03

Joel K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django architecture question


I guess what I'm am trying say is that I was under the impression that
when you go to a URL, a view is called. And only one view can be
called per URL. And that view needs to serve all of the data for that
page. It seems like there is a way to have multiple views being
rendered simultaneously. Is it all javascript or just a huge view
with: user login, feeds of current data, etc...

On Jun 15, 8:09 am, Paul <pkoe...@gmail.com> wrote:
> On 15 Jun., 06:55, Joel Klabo <joelkl...@gmail.com> wrote:
>
> > I am working on a simple site right now and the views are pretty easy.
> > Usually just iterate a loop of objects. But, I am trying to figure out
> > how a website with all different kinds of data, including a sign in
> > form, is setup in django. Is that all in one big view? Or, is there
> > some way to combine them?
>
> > Any insight would be helpful, thank you.
>
> Hi Joel,
>
> very good question, I take it you want to know how "composition" is
> done at the "page level" without dragging all the logic into one view.
> In django you can generate recurring elements with template tags, for
> adding variables to the request or generate markup directly.
>
> say you want a list of users that joined your site recently:
>
> class RecentUsersNode(template.Node):
>     def __init__(self, limit):
>         try: self.limit = int(limit)
>         except ValueError: self.limit = 10
>
>     def render(self, context):
>         profiles = UserProfile.objects.order_by('user__date_joined')
>
>         context = profiles
>         return ''
>
> @register.tag
> def recent_users(parser, token):
>     args = token.split_contents()
>     if len(args) <= 1:
>         return RecentUsersNode(10)
>
>     num = args
>     if(num == num and num in ('"', "'")):
>         num = num # strip quotes
>     return RecentUsersNode(num)
>
> {% recent_users %} will add a list of UserProfile objects to your
> request and you can use it like:
>
> {% for profile in recent_users %}
>   <img src="{{ profile.photo.url }}" alt="{{ profile.desc }}" />
> {% endfor %}
>
> In the old days of web 1.0 there was a natural 1:1 mapping from the
> page to a script/function which generates the content. With ajax it's
> becoming more like a desktop app where you have many parts/widgets
> with callbacks or events. If you want the page to display without JS,
> you still have to generate the page with one request though...
>
> cheers
>  Paul

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support