这是我的Models.py
import argparse
import os
from django.db import models
from django.db import models
from django.contrib.auth.models import User
from oauth2client import tools
from oauth2client.client import flow_from_clientsecrets, Storage
CLIENT_SECRETS = os.path.join(
os.path.dirname(__file__), 'client_secrets.json')
TOKEN_FILE_NAME = 'credentials.dat'
FLOW = flow_from_clientsecrets(
CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/analytics.readonly',
message='%s is missing' % CLIENT_SECRETS
)
def prepare_credentials():
parser = argparse.ArgumentParser(parents=[tools.argparser])
flags = parser.parse_args()
# Retrieve existing credendials
storage = Storage(TOKEN_FILE_NAME)
credentials = storage.get()
# If no credentials exist, we create new ones
if credentials is None or credentials.invalid:
credentials = tools.run_flow(FLOW, storage, flags)
return credentials
class FlowModel(models.Model):
id = models.ForeignKey(User, primary_key=True)
flow = FLOW
class CredentialsModel(models.Model):
id = models.ForeignKey(User, primary_key=True)
credential = prepare_credentials()
当我运行python manage.py runserver时 它给我下面的错误
usage: manage.py [-h] [--auth_host_name AUTH_HOST_NAME]
[--noauth_local_webserver]
[--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
[--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
manage.py: error: unrecognized arguments: runserver 8000
我已尝试搜索解决方案,但此错误仍然存在。 请尽快帮助我解决这个问题。
答案 0 :(得分:2)
尝试替换:
parser = argparse.ArgumentParser(parents=[tools.argparser])
与
parser = tools.argparser.parse_args([])