S
S
Stanislav Shabalin2020-08-31 17:34:23
Django
Stanislav Shabalin, 2020-08-31 17:34:23

NameError at /catalog/tags when accessing an object in a mixin?

Updated and caught a non-typical error:

Django Version: 3.1
Exception Type: NameError
Exception Value: name 'Category' is not defined
Python Version: 3.8.5

catalog_app_name = 'catalog/' # The name of my app

#views.py
from django.http import Http404, HttpRequest, HttpResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.urls import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import EmailMessage
from django.conf import settings
from django.template.loader import render_to_string
from datetime import date

from django.views.generic import View, ListView
from django.views.generic.edit import FormView
from django.core.paginator import Paginator

from .logic import *
from .forms import *

class tags_list(PostListMixin, View):
  model = Tag
  template = 'tags'

#logic.py
from django.shortcuts import render, get_object_or_404
from django.http import Http404

import hashlib
import os
from django.core.files.storage import FileSystemStorage

class PostListMixin:
  model = None
  template = None
  def get(self, request):
    post_list = self.model.objects.all()
    context = {self.template : post_list}
    if self.template == 'tags':
      context['categories'] = Category.objects.all() # <---- ОШИБКА ЗДЕСЬ!!!

    return render(request, catalog_app_name + self.template + '.html', context)


It still worked before the update. Who-thread faced?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question