从myapp导入视图 文件“ C:\ Users \ User \ job \ mysite \ myvenv \ myproject \ myapp \ views.py”,第151行
class MarketingBusinessDetailView(generic.DetailView):
SyntaxError: invalid syntax
在models.py,
class MarketingBusiness(models.Model):
title = models.CharField(max_length=128)
description = models.TextField(max_length=200, help_text="Enter a brief description of the Marketing business.")
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('myapp:marketingbusiness-detail', args=[str(self.id)])
在我的管理员中,它运行良好。
在myapp urls.py,
from myapp import views
app_name = 'myapp'
urlpatterns = [
path('marketingbusinesses/', views.MarketingBusinessListView.as_view(), name='marketingbusiness'),
path('marketingbusiness/<int:pk>/', views.MarketingBusinessDetailView.as_view(), name='marketingbusiness-detail'),
在views.py,
from django.shortcuts import render
from django.views import View
from django.views import generic
from myapp.models import MarketingBusiness
class MarketingBusinessDetailView(generic.DetailView):
model = MarketingBusiness
def marketingbusiness_detail(request, pk):
marketingbusiness_id = get_object_or_404(MarketingBusiness, pk=pk)
return render(
request,
'myapp/marketingbusiness-detail.html', context={'marketingbusiness_id':marketingbusiness}
)
请问如何解决此错误?...