Django 1.4导入url中的错误无效语法

时间:2012-05-19 22:52:55

标签: django apache django-views syntax-error django-urls

我有一个带有2个应用程序的django 1.4项目:RemoteStorage和WeShouldServer(一个在项目创建时自动处理,包含网址,设置等)

当我尝试访问我的管理页面时,出现此错误:

SyntaxError at /admin
invalid syntax (views.py, line 33)

并且堆栈跟踪的最后一行是:

from RemoteStorage.views import refer 

我认为这是一般导入错误,因为我从RemoteStorage.views导入了3个方法,当我更改顺序时,无论第一次导入是什么,我仍然会收到导入错误。

我的urls.py:

from django.conf.urls import patterns, include, url
from RemoteStorage.views import refer
from RemoteStorage.views import check_referrals
from RemoteStorage.views import save_item


# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'WeShouldServer.views.home', name='home'),
    # url(r'^WeShouldServer/', include('WeShouldServer.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^save-item/', save_item),
    url(r'^check-referrals/', check_referrals),
    url(r'^refer', refer),
)

我的settings.py包含我的应用:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    **'RemoteStorage',**
)

my views.py:

# Create your views here.
from RemoteStorage.models import Item, Tag, Category, User, Referral
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
import json

def save_item(request):
        try:

                print request.GET
#               print request.user
                i = Item()
                i.user = User.objects.get_or_create(email=request.GET['user_email'])[0]
#       i.website = request.GET.get('website', "")
#       i.comment = request.GET.get('comment', "")
#       i.rating = request.GET.get('rating', "")
#       i.phone_numger = request.GET.get('phone number', "")
#               i.address = request.GET.get('address', "")      
                i.save()

                print i
        except Exception as e:
                print e.message()

        return HttpResponse()

def check_referrals(request):
        try:
                print request
                user = User.objects.get_or_create(email = request.GET.get("user_email", "")[0]
#       referrals = Referral.objects.filter(referred_to = user)
#       return HttpResponse(content = json.dumps(referrals))
                return HttpResponse()
        except Exception as e:
                print e.message()

def refer(request):
        print request
        user = User.objects.get_or_create(email = request.GET.get("user_email", "")[0]
        refer_to = request.GET.get("email_list", "")
        refer_to_list = refer_to.split(",")

        for rt in refer_to_list:
                r = Referral()
                r.data = request.GET.get("item_data", "")
                r.referred_by = user
                r.referred_to = rt
                r.save()
        return HttpResponse()

我无法弄清楚出了什么问题!

1 个答案:

答案 0 :(得分:1)

检查 32 (33 - 1)

user = User.objects.get_or_create(email = request.GET.get("user_email", "")[0]

它缺少一个正确的parens,应该是

user = User.objects.get_or_create(email = request.GET.get("user_email", ""))[0]