manage.py:错误:无法识别的参数:runserver 8000,Google AnalyticsAPI Django

时间:2017-10-03 18:50:33

标签: python django google-analytics oauth-2.0 google-analytics-api

这是我的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

我已尝试搜索解决方案,但此错误仍然存​​在。 请尽快帮助我解决这个问题。

1 个答案:

答案 0 :(得分:2)

尝试替换:

parser = argparse.ArgumentParser(parents=[tools.argparser])

parser = tools.argparser.parse_args([])