0

i am using Django 1.10.5. this error comes when i click on AttributeError at /rentacar/list/

Views

imports

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),

i am using template as a model and defining the template object and getting it from my template app.is there any easy way to render my template.

Exception Location: D:\buggy\extension\views.py in rentacar_list, line 766

Template Model

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'
17
  • Please show the definition for Template, and also how you're importing it in that view. Commented Sep 5, 2018 at 8:36
  • do i show th template model ? or do i show the html file of this template ? Commented Sep 5, 2018 at 8:39
  • The Template model, and the import statement in this view. Commented Sep 5, 2018 at 8:40
  • @DanielRoseman Please Check i had updated. Commented Sep 5, 2018 at 8:47
  • post the whole traceback Commented Sep 5, 2018 at 8:52

1 Answer 1

1

this Error is Coming due to i am importing my custome model template and built in Template

from template.models import Template
from django.template import Context, Template
def func1(request):

  template = **Template**.objects.get(template_default__exact=1)

def func2(request):            
      template = **Template** ("""link{{ request.get_host }}{% url 'detail' driver_id=driver_id %}""")

Same Template name with different import.One is built-in import and second is model import thats why attribute error is occuring.

Special Thanks to :

Willem Van Onsem

Alasdair

Daniel Roseman

this answer resolve by these great men.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.