使用Django访问imdb数据

时间:2015-05-24 08:04:40

标签: python django

我正在尝试创建一个django应用程序,因为我正在使用django学习探戈(http://www.tangowithdjango.com/)..the应用程序基于imdb-pie客户端(https://github.com/pravarag/imdb-pie),它将显示来自imdb的数据当他/她登录到他们的帐户时,特定用户。但是当我尝试运行代码时,没有与客户端建立连接,也没有从站点检索到任何内容并显示空结果。 这是我的views.py文件:

from django.shortcuts import render

from imdbpie import Imdb

from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout

from django.http import HttpResponseRedirect, HttpResponse

from datetime import datetime


imdb = Imdb()

def index(request):
    pass



def user_login(request):

    context_dict={}

    top250=imdb.top_250()

    lst=[]

    for i in top250:
        for k, v in i.items():
            if k=="title":
                lst.append(v)

    context_dict['moviesTop250']=lst


    if request.method=="POST":
        username=request.POST.get('username')
        password=request.POST.get('password')

        user=authenticate(username=username, password=password)

        if user:

            if user.is_active:
                login(request, user)
                return HttpResponseRedirect('/imdbApp')
            else:
                return HttpResponse("Your Rango account is disabled")
        else:
            print("Invalid login details: {0}, {1}".format(username, password))
            return HttpResponse("Invalid Login details supplied")
    else:
        return render(request, 'imdbApp/login.html', context_dict)


@login_required
def restricted(request):
    return HttpResponse("")


@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect("/imdbApp/")

def homepage(request):
    pass

def result(request):
    pass

这是我的登录模板(login.html)

<!DOCTYPE html>
{% load static %}
<html>
<head>
    <title>Welcome to the ImdbApp</title>
</head>
<body>
<h1>Login</h1>
    <form id="login_form" method="post" action="/imdbApp/login">
            {% csrf_token %}
            Username: <input type="text" name="username" value="" size="50"/><br/>
            Password: <input type="password" name="password" value="" size="50"/><br/>
            <input type="submit" value="submit" />
    </form>

    <h4><a href="/imdbApp/register/">Register new User!!</a></h4>

    <p>
        {% if moviesTop250 %}
            <ul>
                {% for i in moviesTop250 %}
                    {% for j in i %}
                        <li>{{ j }}</li>
                    {% endfor %}
                {% endfor %}
            </ul>
        {% else %}
            <STRONG>Nothing here "SIRE"</STRONG>
        {% endif %}


    </p>

</body>
</html>

所以不要在登录页面上显示前250个结果,而是看到“Nothing here sire”msg,这意味着没有与imdb-pie客户端建立连接。我在virtualenv上运行整个django项目我的操作系统是OS X 10.10 .. imdb-pie客户端安装在安装了django的同一目录下。我应该尝试将它安装在我的app目录中吗?

0 个答案:

没有答案