Я использую Django 1.10.5. эта ошибка возникает, когда я нажимаю на
AttributeError в / rentacar / list /
Просмотры
импорт
from rentacar.forms import *
from template.models import Template
from module.models import *
@csrf_protect
def rentacar_list(request, page_number=1):
menu_config_list = MenuItemRentacarList.objects.all()[0]
menu_config = MenuItemRentacarList.objects.get(id=menu_config_list.id)
all_cars = Car.objects.all().order_by('-id')
if menu_config.menu_item_rentacar_list_show_unavailable == 0:
all_cars = all_cars.exclude(car_available=0)
else:
all_cars = all_cars
cars_page = Paginator(all_cars, menu_config.menu_item_rentacar_list_pagination)
args['cars'] = cars_page.page(page_number)
template = Template.objects.get(template_default__exact=1)
args['main_menu'] = MenuMenu.objects.get(id__exact=template.template_main_menu_id)
args['menu_items'] = MenuItem.objects.filter(
menu_item_menu=args['main_menu'],
menu_item_published=1,
)
template_page = template.template_alias + str("/rentacar/rentacar_cars_list.html")
args['current_menu_item'] = menu_config.menu_item_rentacar_list_menu_item
all_modules = Module.objects.filter(
module_show_option__exact='all',
module_published=1
)
selected_modules = Module.objects.filter(
module_show_option__exact='selected',
module_published=1,
module_menu_item=args['current_menu_item']
)
excluded_modules = Module.objects.filter(
module_show_option__exact='except',
module_published=1,
).exclude(
module_menu_item=args['current_menu_item']
)
args['modules'] = list(chain(all_modules, selected_modules, excluded_modules))
return render(request, template_page, args)
Urls
url(r'^rentacar/list/$', extension_views.rentacar_list),
Я использую шаблон в качестве модели, определяю объект шаблона и получаю его из моего приложения-шаблона. Есть простой способ визуализации моего шаблона.
Местоположение исключения : D: \ buggy \ extension \ views.py в rentacar_list, строка 766
Шаблон модели
from mega_admin.models import MenuMenu
class Template(models.Model):
class Meta():
db_table = "template"
verbose_name = "Template"
verbose_name_plural = "Templates"
template_title = models.CharField(
verbose_name="Template title",
max_length=200
)
template_alias = models.CharField(
verbose_name="Template alias",
max_length=200
)
template_description = models.TextField(
verbose_name="Template description",
blank=True,
)
template_version = models.IntegerField(
verbose_name="Template version",
null=True,
blank=True,
)
template_default = models.BooleanField(
default=0,
blank=False,
null=False
)
template_main_menu = models.ForeignKey(
MenuMenu,
blank=True,
null=True,
on_delete=models.CASCADE,
)
def __unicode__(self):
return u'%s' % self.template_title + str(" v") + str(self.template_version)
class TemplatePosition(models.Model):
class Meta():
db_table = "template_position"
verbose_name = "Template position"
verbose_name_plural = "Template positions"
template_position_template = models.ForeignKey(
'template.Template',
related_name="template_position_template_key",
verbose_name="Template positions template",
blank=False,
null=False,
on_delete=models.CASCADE,
)
template_position_name = models.CharField(
verbose_name="Template position name",
max_length=200,
blank=False,
null=False,
)
template_position_alias = models.CharField(
verbose_name="Template position alias",
max_length=200,
blank=False,
null=False,
)
# def __unicode__(self):
# return u'%s' % self.template_position_name
Traceback
File "D:\projects\buggy\venv\lib\site-packages\django\core\handlers\exception.py" in inner
39. response = get_response(request)
File "D:\projects\buggy\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "D:\projects\buggy\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\projects\buggy\venv\lib\site-packages\django\utils\decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "D:\buggy\extension\views.py" in rentacar_list
766. template = Template.objects.get(template_default__exact=1)
Exception Type: AttributeError at /rentacar/list/
Exception Value: type object 'Template' has no attribute 'objects'