In the views.py when we insert models or forms why we don't use "from . import models" instead of "from .models import Model1,Model2?

we import views in urls.py urls.py

from django.urls import path
from . import views
urlpatterns = [

    path('',views.index,name='index'),
    path('posts',views.all_posts,name='all'),
    path('posts/<slug:slug>',views.post_details,name='post_details')

]

in views.py models and forms are imported like views.py

from django.shortcuts import render
from .models import Post,Author,Tag,Comment
from .forms import CommentForm

def index(request):
    posts = Post.objects.all()
    print(posts)
    return render (request,'mblog/index.html',{'all_posts': posts})

def all_posts(request):
    posts = Post.objects.all()
    return render (request,'mblog/all-posts.html',{'all_posts': posts})
Back to Top