当我尝试进入asset_list视图时,它挂在Option Explicit
Sub numberfiller()
Dim i As Long
Dim maxrow As Long
i = 2
maxrow = 100
With ThisWorkbook.Worksheets(1)
While Not IsEmpty(.Range("A" & i).Value) And i < maxrow
If Not .Range("A" & i).Value = .Range("A" & i - 1).Value + 1 Then
.Range("A" & i).EntireRow.Insert shift:=xlDown
.Range("A" & i).Value = .Range("A" & i - 1).Value + 1
Else
i = i + 1
End If
Wend
End With
End Sub
上并抛出错误
get_absolute_url()
我正在网站上使用一堆此资产应用程序的实例,每个实例将基于标签属性提供一些不同的资产。 Apphooks运作良好,所有内容都附在cms中。在开始尝试细节视图之前,我已完成所有工作。我认为我有两个问题,一个是Reverse for 'asset_detail' with keyword arguments '{'id': 1}' not found. 1 pattern(s) tried: ['en/marketing/$/<int:id>/']
,另一个是get_absolute_url
这就是我所拥有的
urls.py
urls.py
models.py
from django.conf.urls import url, include
from .views import AssetListView, AssetDetailView
app_name = 'assets'
urlpatterns = [
# List View
url(r'^$', AssetListView, name="asset_list"),
url(r'^$/<int:id>/', AssetDetailView, name='asset_detail')
]
views.py
class Asset(models.Model):
name = models.CharField(max_length=50, blank=False)
description = PlaceholderField('asset_description')
asset_category = models.ManyToManyField(Asset_Category, blank=True)
tag = models.ManyToManyField(Tag, blank=True)
product_category = models.ManyToManyField(Category, blank=True)
product_series = models.ManyToManyField(Series, blank=True)
product_line = models.ManyToManyField(Line, blank=True)
product = models.ManyToManyField(Product, blank=True)
url = models.CharField(max_length=250, blank=True, verbose_name='Video URL')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_active = models.BooleanField(default=True)
def get_absolute_url(self):
return reverse("assets:asset_detail", kwargs={"id": self.id})
asset_view.html
def AssetListView(request, *args, **kwargs):
path = os.path.basename(os.path.normpath(request.path))
print(path)
page_obj = Title.objects.filter(slug=path).first()
print (page_obj)
for obj in Tag.objects.all():
print (obj.name)
if obj.name == page_obj.title:
queryset = Asset.objects.filter(tag=obj.id)
context = {
'object_list': queryset,
}
return render(request, 'asset_view.html', context)
queryset = Asset.objects.all()
context = {
'object_list': queryset,
}
return render(request, 'asset_view.html', context)
def AssetDetailView(request, *args, **kwargs):
return HttpResponse('<h1>AssetDetailView<h1>')
答案 0 :(得分:2)
URL无效,您不能在此处插入$
锚点,因为$
表示字符串的 end 。此外,由于您使用url(..)
,因此它应该是正则表达式,例如:
url(r'^(?P\d+)/$', AssetDetailView, name='asset_detail')
请注意,PEP-8建议以小写形式编写函数名称,并在单词之间使用下划线。因此,我建议将函数重命名为asset_detail_view
和asset_list_view
。