jazzband / django-embed-video

Django app for easy embedding YouTube and Vimeo videos and music from SoundCloud.
http://django-embed-video.rtfd.org
MIT License
382 stars 135 forks source link

How to Validate youtube url before saving #31

Closed sunjoomoon closed 10 years ago

sunjoomoon commented 10 years ago

How to validate if youtube video url format is correct before saving? Wrong url format saved returns error both in the browser and admin page.

yetty commented 10 years ago

Please provide more details about your problem - I need to know exact url to determine the problem. It should be helpful to provide you version of django-embed-video, too. Validation in administration should work fine.

sunjoomoon commented 10 years ago

sorry for the late one. here comes my environment- django-embed-video==0.9 and django == 1.6.5

Enterting correct url like below, http://www.youtube.com/watch?v=gauN0gzxTcU -> works fine

but often clients enter wrong youtube url.. for example, http://www.youtube.com/edit?video_id=eBea01qmnOE returns below

Error during template rendering

In template /../../embed_video/templates/embed_video/embed_code.html, error at line 1
(Could not get exception message)
1   <iframe width="{{ width }}" height="{{ height }}" src="{{ backend.url }}" class="video-frame" allowfullscreen></iframe>

So, hope if youtube video url format is not correct, then show warning message while saving. Any advice? Thanks.

yetty commented 10 years ago

Validation of urls has been improved, so if you use EmbedVideoFormField, invalid urls will raise ValidationError.

sunjoomoon commented 10 years ago

Thank you Juda. As per your advice, all went fine now. I upgraded to 0.10. I repeated the same and here is the result. 1) http://www.youtube.com/edit?video_id=eBea01qmnOE #saved ok, video plays in browser. OK 2) wrong url was tried but warning message came up before saving, like a typical django message. Thanks again, this helps me and clients as well a lot.

mpachas commented 10 years ago

Thank you guys, this is really helpful.