manage.py: error: unrecognized arguments: runserver 8000, Google Analytics API Django

与世无争的帅哥 提交于 2019-12-08 09:36:51

问题


Here is my 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()

When I run python manage.py runserver It gives me the error below

      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

I have tried searching for solutions but this error still persists. Kindly help me solve this as I am running out of time.


回答1:


Try to Replace:

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

with

parser = tools.argparser.parse_args([])


来源:https://stackoverflow.com/questions/46551454/manage-py-error-unrecognized-arguments-runserver-8000-google-analytics-api-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!