开发者

Breaking Django views into seperate directories and files

开发者 https://www.devze.com 2023-02-06 16:09 出处:网络
I\'m quite new to Django and I\'m enjoying it a lot开发者_StackOverflow. I have broken my app\'s views into different files and placed them in a directory called app/views/(view files).

I'm quite new to Django and I'm enjoying it a lot开发者_StackOverflow. I have broken my app's views into different files and placed them in a directory called app/views/(view files).

I have made an __init__.py file in the views directory this has caused me to have to use myproj.app.views.views in my site code. Which of coarse not very digestible.

Any ideas around this. Or is renaming my views directory to something else the way forward.

Thanks.


Just import the views from the other modules in __init__.py.


My user profile app account has three views files: views.py, views_login.py, and views_profile.py. Maybe it's not the cleanest, but it separates the three parts of account pretty well for my needs. My apps/account/urls.py therefore looks like this:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^foo1$', 'apps.account.views.foo1'),
    (r'^foo2$', 'apps.account.views.foo2'),
    (r'^bar1$', 'apps.account.views_login.bar1'),
    (r'^bar2$', 'apps.account.views_login.bar2'),
    (r'^baz1$', 'apps.account.views_profile.baz1'),
    (r'^baz2$', 'apps.account.views_profile.baz2'),
)
0

精彩评论

暂无评论...
验证码 换一张
取 消