On Jun 27, 8:47 am, Reza Muhammad <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I just started learning about python and django. For the past months I
> was working on a project using a PHP framework (I guess, the name
> would not be important right now :).  For my initial experiment, I
> would like to port my last project that I used with PHP to django.
> The project contains 10 tables, and most of them have relationships
> between one another.  So, I think this is considered as one
> application.
>
> Anyway, I am used to having separate files to facilitate different
> controllers (I think it's called views in django).  On the other hand,
> django uses one views.py for one application.  Is there anyway I can
> have a views/parts.py or parts_views.py that interacts with part
> model, or something like that? Because  currently, I have about 60
> functions in my PHP's controllers that I want to port to django.  So,
> that will mean 60 functions in views.py right? Is this the right way
> to do it?  Or can I separate those functions into multiple views?
>
> Thanks for your help :)
> Reza Muhammad

Views are just Python functions. You can have any number of views, and
they can live in any number of separate files. You just need to
reference them properly in the urls.py file, to map a URL to the
specific view and the module it is in. The default views.py that is
created by the create_app command is just a template - in fact you can
do anything you like.

I'm not sure from your question whether you mean 60 separate views, or
whether some of the 60 functions you mention are utility functions.
Either way, you can separate them out in any way you find logical. If
they are utility functions, you can just import them at the top of
your main views.py file. If they are actual views, you can just refer
to them from urls.py.

For example, your urls.py might look like this:
...
urlpatterns = patterns('',
    (r'^articles/$', 'views.index'),
    (r'^articles/(\d{4})/$', 'views.year_archive'),
...
    (r'^special/$', 'special_views.index'),
)

etc., where there are two files containing views - views.py and
special_views.py.

Hope this helps.

--
DR.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to