Can we make another folder inside a view folder inside which we can keep a specific view file?


I used

Python 3.7
Django 2.0
My Project Name : fusion
My App Name : django_adminlte

issues is views normalization not working for views folder structure,I want Split in several separated folder inside another separated folder due to lots of views files.

I already do this things with model but unfortunately cant work with views folder.i do all require file put in app .( i file also)

you assume that i want it like - example path dir

I want this type of setup for views file.

how can i do it ,which changes required in flow ?

(Vitor Freitas) #2

This is perfectly fine, you can keep this folder structure as you described, with views/sub_views, etc.

Then in your you simply import the views accordingly, like this:

from django.urls import path

from import views1
from import views2

urlpatterns = [
    path('homepage/', views1.homepage_view, name='homepage'),
    path('about/', views2.about_view, name='about'),

If you have name conflict you can rename the views module on import, like this:

from import views1 as sub_views2_views1

urlpatterns = [
    # ...
    path('privacy/', sub_views2_views1.privacy, name='privacy'),

In fact Django doesn’t really care where the view function/class is stored. All you have to do is to provide the link between the url and the view on your module

It’s a little bit different with models because Django expect to find your models inside the file


Awesome its excellent working ,how can i forget it silly mistake,Thank you so much big bro vitor