RemoteStorage と WeShouldServer の 2 つのアプリを含む django 1.4 プロジェクトがあります (プロジェクトの作成時に自動作成され、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',**
)
私の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()
何が悪いのかわからない!