Django属性错误。 'module'对象没有属性'XYZ'

时间:2014-03-27 08:45:05

标签: python django

所以这是我的urls.py

from django.conf.urls import patterns, include, url
from v1_1 import views

urlpatterns = patterns('',
    url(r'', include('social_auth.urls')),
    url(r'^$', views.fblogin),                      ### LINE1
    url(r'^logged-in/$', 'v1_1.views.fb_loggedin'), ### LINE2
)

由于LINE1,它会导致错误。它(相同的代码)曾经用于工作一段时间。如果我将LINE1更改为url(r'^$', 'v1_1.views.fblogin'),它工作正常...我无法理解问题:/

这是我的views.py

from django.http import HttpResponse
from django.template import RequestContext, Context, Template
from django.template.loader import get_template
from kb_db1.models import User
from django.core.exceptions import ObjectDoesNotExist
import datetime

def home(request):
    t = get_template('profile.html')
    c = get_user(1)
    r = t.render(c)
    return HttpResponse(r)

def fblogin(request):
    t = get_template('login.html')
    c = Context({'name':'Suneet' , 'STATIC_URL':'/stic' , })
    r = t.render(c)
    return HttpResponse(r)

def fb_loggedin(request):
    t = get_template('profile.html')
    user = request.user
    c = get_user(user)
    #c = Context({'user2':user , 'fb_app_id':'139460226147895', 'app_scope':'email', 'STATIC_URL':'/stic' , })
    r = t.render(c)
    return HttpResponse(r)

def notfound(request):
    t = get_template('404.html')
    c = Context({'name': 'Adrian', 'section.title': 'Suneet'})
    r = t.render(c)
    return HttpResponse(r)

def display_meta(request):
    t = get_template('done.html')
    c = get_user(2)
    #return render(request, t, {'m_list': m_list})
    r = t.render(c)
    return HttpResponse(r)

def get_user(user):
    id = user.id
    try:
        u_list = User.objects.get(id=id)
        try:
            u_list.profile = u_list.get_profile()
            u_list.profile = prettify_user(u_list.profile)
        except ObjectDoesNotExist:
            u_list.profile = u_list
            u_list.profile.cumulative_rating = '- '
        c = Context({'u_list':u_list, 'user2':user, 'STATIC_URL':'/stic'})
    except ObjectDoesNotExist:
        print("Either the entry or blog doesn't exist.")
        c = Context({ 'name': 'Error', 'user2':user, 'fb_app_id':'139460226147895', 'STATIC_URL':'/stic'})
    return c

def prettify_user(user):
    try:
        confident_rating, confident_votes = calc_rating(user.cumulative_rating, user.cumulative_votes, 5.2, 5)
        user.cumulative_rating = "%.0f" %(confident_rating*10) # 9.750 => 97.50 => 98       |   9.749 => 97.49 => 97.4
        user.cumulative_votes = confident_votes
    except ObjectDoesNotExist:
        user = 'me'
    return user

def calc_rating(rating, votes, fake_rating_val, fake_votes_no):
    total_votes = votes+fake_votes_no
    rating = (float(rating*votes) + fake_rating_val*fake_votes_no)/total_votes
    return rating, total_votes

def chck_anon(user):
    if not user.is_anonymous:
        user.is_anonymous = True
    return user

0 个答案:

没有答案