我有一个带有 2 个应用程序的 django 1.4 项目:RemoteStorage 和 WeShouldServer(那个是在项目创建时自动创建的,包含 url、设置等)
当我尝试转到我的管理页面时,我收到此错误:
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',**
)
我的意见.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()
我不知道出了什么问题!