问题
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