DjangoでYouTubeAPIを使いチャンネル登録者数の情報を得たい
djangoを使って上記のような関数を作っていたのですがタプルのエラーが出てきてうまくいきません。
発生している問題・エラーメッセージ
[29/Sep/2020 10:19:30] "GET /accounts/create/ HTTP/1.1" 200 621 Internal Server Error: /accounts/create/ Traceback (most recent call last): File "C:\Users\takara\miniconda3\envs\ex2020\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\Users\takara\miniconda3\envs\ex2020\lib\site-packages\django\utils\deprecation.py", line 96, in __call__ response = self.process_response(request, response) File "C:\Users\takara\miniconda3\envs\ex2020\lib\site-packages\django\middleware\clickjacking.py", line 26, in process_response if response.get('X-Frame-Options') is not None: AttributeError: 'tuple' object has no attribute 'get'
該当のソースコード
python
1@login_required 2def create(request): 3 4 params ={ 5 'title':'let input your channel_id', 6 'form' : ChannelForm(), 7 } 8 if (request.method == 'POST'): 9 user = request.user 10 channel_id = request.POST['channel_id'] 11 youtube = build("youtube","v3",developerKey=api_key) 12 request = youtube.channels().list( 13 part="snippet,contentDetails,statistics", 14 id=channel_id, 15 ) 16 response = request.execute() 17 counts = response['items'][0]['statistics']['subscriberCount'] 18 channel_subr = counts 19 rink_id = random.randrange(1000, 100000) 20 channel = Channel(owner = user, channel_id = channel_id, channel_subr = channel_subr, rink_id = rink_id ) 21 channel.save() 22 params_i ={ 23 'title' : 'use URL + this number', 24 'number' : counts, 25 } 26 return (request,'home.html',params_i) 27 28 29 30 31 return render(request, 'accounts/create.html',params) 32 33 34 35
html
1---home.html--- 2{% extends 'base.html' %} 3 4{% block title %}Home{% endblock %} 5 6{% block content %} 7{% if user.is_authenticated %} 8 Hi {{ user.username }}! 9 <a href="accounts/create">ランキング参加用URL発行はこちら</a> 10 {{title}}{{number}} 11{% else %} 12 <p>You are not logged in</p> 13 <a href="{% url 'login' %}">Log In</a> 14{% endif %} 15{% endblock %} 16 17---create.html--- 18{% extends 'base.html' %} 19 20{% block title %}Home{% endblock %} 21 22{% block content %} 23{% if user.is_authenticated %} 24 Hi {{ user.username }}! 25 <h1>{{title}}</h1> 26 <table> 27 <form action="{% url 'create' %}" method="post"> 28 {% csrf_token %} 29 {{ form.as_table }} 30 <tr><td></td><td><input type="submit" value ="click"></td></tr> 31 </form> 32 </table> 33{% else %} 34 <p>You are not logged in</p> 35 <a href="{% url 'login' %}">Log In</a> 36{% endif %} 37{% endblock %} 38
ディレクトリ
│ db.sqlite3
│ manage.py
│
├─accounts
│ │ admin.py
│ │ apps.py
│ │ forms.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ init.py
│ │
│ ├─migrations
│ │ │ 0001_initial.py
│ │ │ 0002_remove_channel_money.py
│ │ │ 0003_channel_rink_id.py
│ │ │ 0004_auto_20200928_1642.py
│ │ │ 0005_auto_20200928_1934.py
│ │ │ 0006_auto_20200928_1943.py
│ │ │ init.py
│ │ │
│ │ └─__pycache__
│ │ 0001_initial.cpython-38.pyc
│ │ 0002_remove_channel_money.cpython-38.pyc
│ │ 0003_channel_rink_id.cpython-38.pyc
│ │ 0004_auto_20200928_1642.cpython-38.pyc
│ │ 0005_auto_20200928_1934.cpython-38.pyc
│ │ 0006_auto_20200928_1943.cpython-38.pyc
│ │ init.cpython-38.pyc
│ │
│ └─__pycache__
│ admin.cpython-38.pyc
│ forms.cpython-38.pyc
│ models.cpython-38.pyc
│ urls.cpython-38.pyc
│ views.cpython-38.pyc
│ init.cpython-38.pyc
│
├─config
│ │ asgi.py
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ init.py
│ │
│ └─__pycache__
│ settings.cpython-38.pyc
│ urls.cpython-38.pyc
│ wsgi.cpython-38.pyc
│ init.cpython-38.pyc
│
└─templates
│ base.html
│ home.html
│
├─accounts
│ create.html
│
└─registration
login.html
signup.html
回答1件
あなたの回答
tips
プレビュー