django_youtube/views.py
def upload(request):
    """
    Displays an upload form
    Creates upload url and token from youtube api and uses them on the form
    """
    # Get the optional parameters
    title = request.GET.get("title", "%s's video on %s" % (
        request.user.username, request.get_host()))
    description = request.GET.get("description", "")
    keywords = request.GET.get("keywords", "")

    # Try to create post_url and token to create an upload form
    try:
        api = Api()

        # upload method needs authentication
        api.authenticate()

        # Customize following line to your needs, you can add description, keywords or developer_keys
        # I prefer to update video information after upload finishes
        data = api.upload(title, description=description, keywords=keywords,
                          access_control=AccessControl.Unlisted)
    except ApiError as e:
        # An api error happened, redirect to homepage
        messages.add_message(request, messages.ERROR, e.message)
        return HttpResponseRedirect("/")
    except:
        # An error happened, redirect to homepage
        messages.add_message(request, messages.ERROR, _(
            'An error occurred during the upload, Please try again.'))
        return HttpResponseRedirect("/")

    # Create the form instance
    form = YoutubeUploadForm(initial={"token": data["youtube_token"]})

    protocol = 'https' if request.is_secure() else 'http'
    next_url = '%s://%s%s/' % (protocol, request.get_host(), reverse("django_youtube.views.upload_return"))
    return render_to_response(
        "django_youtube/upload.html",
        {"form": form, "post_url": data["post_url"], "next_url": next_url},
        context_instance=RequestContext(request)
    )
def upload(request):
    """
    Displays an upload form
    Creates upload url and token from youtube api and uses them on the form
    """
    # Get the optional parameters
    title = request.GET.get("title", "%s's video on %s" % (
        request.user.username, request.get_host()))
    description = request.GET.get("description", "")
    keywords = request.GET.get("keywords", "")

    # Try to create post_url and token to create an upload form
    try:
        api = Api()

        # upload method needs authentication
        api.authenticate()

        # Customize following line to your needs, you can add description, keywords or developer_keys
        # I prefer to update video information after upload finishes
        data = api.upload(title, description=description, keywords=keywords,
                          access_control=AccessControl.Unlisted)
    except ApiError as e:
        # An api error happened, redirect to homepage
        messages.add_message(request, messages.ERROR, e.message)
        return HttpResponseRedirect("/")
    except:
        # An error happened, redirect to homepage
        messages.add_message(request, messages.ERROR, _(
            'An error occurred during the upload, Please try again.'))
        return HttpResponseRedirect("/")

    # Create the form instance
    form = YoutubeUploadForm(initial={"token": data["youtube_token"]})

    protocol = 'https' if request.is_secure() else 'http'
    next_url = '%s://%s%s/' % (protocol, request.get_host(), reverse("django_youtube.views.upload_return"))
    return render_to_response(
        "django_youtube/upload.html",
        {"form": form, "post_url": data["post_url"], "next_url": next_url},
        context_instance=RequestContext(request)
    )
Displays an upload form
    Creates upload url and token from youtube api and uses them on the form