Objects and attribute errors on browser, after server runs

牧云@^-^@ 提交于 2019-12-13 03:25:55

问题


I'm new to Django and I'm working on an app that display the objects of a primary key. The server runs fine but I get an error on the browser that says:

 'master_courses' objects has no attribute 'masterCourses_slug'

The code looks like this:

from django.shortcuts import render, redirect 
from .models import master_courses, course_category, course_series

def single_slug(requests, single_slug):
    categories = [c.course_slug for c in course_category.objects.all()]
    if single_slug in categories:
        matching_series = course_series.objects.filter(course_category__course_slug=single_slug)

        series_urls = {}
        for ms in matching_series.all():
            part_one = master_courses.objects.filter(course_series__course_series=ms.course_series).earliest("date_added") 
            series_urls[ms] = part_one return render(request, "main/category.html", {"the_series": series_urls})

    masterCourses = [ m.masterCourses_slug for m in master_courses.objects.all()]
    if single_slug in masterCourses:
        return HttpResponse(f"{single_slug} is a single slug.")

The error points to the code below (which is on the last line of the code above:

masterCourses = [ m.masterCourses_slug for m in master_courses.objects.all()]
if single_slug in masterCourses:
    return HttpResponse(f"{single_slug} is a single slug.")

The error isn't on the code section, but on the browser.

Any suggestions on how I could Sol this please.

来源:https://stackoverflow.com/questions/57177758/objects-and-attribute-errors-on-browser-after-server-runs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!