Reputation: 349
I am trying to build a Blog application. Ran makemigrations and migrate and also created superuser. But I am getting below error while running the server.
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'blog.templatetags.blog_tags': cannot import name 'POST' from 'blog.models'
Please help me.... My models.py file is
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from django.urls import reverse
# Create your models here.
class CustomManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(status='published')
from taggit.managers import TaggableManager
class Post(models.Model):
STATUS_CHOICES=(('draft','Draft'),('published','Published'))
title=models.CharField(max_length=256)
slug=models.SlugField(max_length=264,unique_for_date='publish')
author=models.ForeignKey(User,related_name='blog_posts',on_delete=models.DO_NOTHING)
body=models.TextField()
publish=models.DateTimeField(default=timezone.now)
created=models.DateTimeField(auto_now_add=True)
updated=models.DateTimeField(auto_now=True)
status=models.CharField(max_length=10,choices=STATUS_CHOICES,default='draft')
objects=CustomManager()
tags=TaggableManager()
class Meta:
ordering=('-publish',)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post_detail',args=[self.publish.year,self.publish.strftime('%m'),self.publish.strftime('%d'),self.slug])
class Comment(models.Model):
post=models.ForeignKey(Post,related_name='comments',on_delete=models.DO_NOTHING)
name=models.CharField(max_length=40)
email=models.EmailField()
body=models.TextField()
created=models.DateTimeField(auto_now_add=True)
updated=models.DateTimeField(auto_now=True)
active=models.BooleanField(default=True)
class Meta:
ordering=('-created',)
def __str__(self):
return 'Commented by {} on {}'.form(self.name,self.post)
Upvotes: 2
Views: 12686
Reputation: 308779
It looks like you have
from blog.models import POST
in blog/templatetags/blog_tags.py
.
Capitalisation matters in Python variable names. It should be:
from blog.models import Post
Upvotes: 1