You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django Wagtail嵌入视频不显示:画廊页面点击后视频无法加载求助

Troubleshooting Video Display Issues on HomePageGallery

Hey there! Let's work through why your videos aren't showing up after clicking into the HomePageGallery page. Here are the most common areas to check and fix:

  • Verify your Model's video field setup
    Make sure you're using the correct field type for storing videos and that the upload path is configured properly. For example, in your models.py:

    class HomePageGallery(models.Model):
        # Add other necessary fields (like thumbnail, title, etc.)
        video = models.FileField(upload_to='gallery_videos/', blank=True, null=True)
        # Don't forget to run migrations after making changes!
    

    Double-check that you've run python manage.py makemigrations and python manage.py migrate to apply any field changes.

  • Confirm your View passes video data to the template
    Ensure your view is fetching the correct HomePageGallery instance and passing it to the template context. For a function-based view:

    def gallery_detail(request, gallery_id):
        gallery_item = HomePageGallery.objects.get(id=gallery_id)
        return render(request, 'home_page_gallery.html', {'gallery_item': gallery_item})
    

    For class-based views, make sure you're using DetailView with the correct model and template name.

  • Fix your template's video rendering code
    In home_page_gallery.html, you need to correctly reference the video's URL and use a valid HTML5 <video> tag. Here's a reliable example:

    {% if gallery_item.video %}
        <div class="video-container">
            <video controls width="640" height="360">
                <source src="{{ gallery_item.video.url }}" type="video/mp4">
                <!-- Add other source tags for different formats if needed -->
                Your browser doesn't support HTML5 video playback.
            </video>
        </div>
    {% else %}
        <p>No video has been added to this gallery item yet.</p>
    {% endif %}
    

    Make sure you're using the same variable name (gallery_item in this case) that you passed from your view.

  • Check your media file configuration
    If the video file is uploaded but not accessible, your Django media settings might be misconfigured. In settings.py:

    MEDIA_ROOT = BASE_DIR / 'media'
    MEDIA_URL = '/media/'
    

    And in your root urls.py, add this to serve media files in development:

    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns = [
        # Your existing URL patterns
    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    

    Note: For production, you'll need to configure your web server (like Nginx or Apache) to serve media files instead of relying on Django's static helper.

  • Debug with browser developer tools
    Open your browser's dev tools (press F12), go to the Network tab, and reload the page. Look for your video file in the requests—if it returns a 404 error, the path in your template is incorrect. Check the Console tab for any JavaScript or HTML errors that might block video rendering.

  • Validate file existence and permissions
    Navigate to the media/gallery_videos/ directory (or whatever upload_to path you set) on your server. Confirm the video file exists there, and that the server has read permissions for the file and directory.

内容的提问来源于stack exchange,提问作者Adrian Covaci

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:26:54