目前我正在使用这样的,但没有工作。。。。我试着签入这两个类,但都不起作用(UserPage和UserPageCarousel),但都不起作用。你知道吗
class UserPageCarousel(Orderable):
def get_context_data(self, request):
context = super(UserPageCarousel, self).get_context(request)
products = UserPageCarousel.objects.all()
print(products)
n = len(products)
nslides = n // 4 + ceil((n / 4) - (n // 4))
context['no_of_slides'] = nslides
context['range'] = range(1, nslides)
context['product'] = products
return context
page = ParentalKey("user.UserPage", related_name="carousel_videos", null=True)
carousel_video = models.ForeignKey(
"wagtailvideos.Video",
related_name="+",
null=True,
blank=False,
on_delete=models.SET_NULL)
panels = [
VideoChooserPanel('carousel_video')
]
class UserPage(Page):
content_panels = Page.content_panels + [
MultiFieldPanel([
InlinePanel('carousel_videos', label="Video")
], heading="Add Videos To List")
]
class Meta:
verbose_name = "User Page"
verbose_name_plural = "User Pages"
这是我的模板(路径是user/user_页面.html) 代码:-你知道吗
<p> Welcome Hi </p>
{% if request.user.is_authenticated %}
{{ user.username }}
{% endif %}
{% for loop_cycle in self.carousel_videos.all %}
<p>{{ loop_cycle.carousel_video.url }}</p>
{% endfor %}
{% for i in range %}
<p> {{ i }}</p>
{% endfor %}
所有的模板代码都在运行,但是对于i in range,没有给出任何东西意味着get上下文在任何情况下都不起作用
电流输出:-
Welcome Hi Hahaha
puneet
/media/original_videos/horse_rolling_farm_animal_equine_1067.mp4
/media/original_videos/horse_rolling_farm_animal_equine_1067_ME9ybb0.mp4
/media/original_videos/horse_rolling_farm_animal_equine_1067_Ix4pCIa.mp4
/media/original_videos/Horses_2.mp4
/media/original_videos/horse_rolling_farm_animal_equine_1067_rhDf82J.mp4
你的
get_context
方法应该在页面对象(UserPage
)上,而不是它的子对象上——它应该被命名为get_context
,而不是get_context_data
。你知道吗相关问题 更多 >
编程相关推荐