我建議在您的Django項目的應用程序文件夾中創建功能子目錄。然後,只需使用from ... import *
咒語,使用app.views
命名空間從新目錄中導入它們即可。這將導入任何視圖,而不需要預先指定模塊名稱(例如,通常會被app_name.views.feature_one.view_class
引用的視爲您想要的app_name.views.view_class
)。請看下圖:
# app_name/views.py
from feature_one.views import *
from feature_two.views import *
# ... copy views from here
# new file: app_name/feature_one/views.py
# ... paste some views here
# new file: app_name/feature_two/views.py
# ... paste some other views here
# new file: app_name/feature_one/__init__.py
# ... this file can be blank. required for importing "feature_one" like a module
# new file: app_name/feature_two/__init__.py
# ... this file can be blank. required for importing "feature_two" like a module
現在,當你的意見將跨越的子目錄傳播,它們都具有相同名稱爲app_name.views
進口,所以你仍然可以引用urls.py
相同的名稱儘管已經移動了一些看法到其他文件。
謝謝,那是我正在尋找的確認。 –