LoginSignup
12
11

More than 3 years have passed since last update.

【音速】python初心者が爆速でDjangoでLINEbotを作成した話

Posted at

LINE Developersにアクセスする

https://developers.line.biz/ja/
このURLからmessageAPIの今すぐ始めようをクリックし、ログインする。

LINE Developersに登録する(初期設定)

チャンネル作成自体は特に難しい事はありません。言われるがままに身を任せて・・・
スクリーンショット 2021-05-08 午後4.13.17.png

画像の下にあるはずのchannelIDとChannelSecretはメモをしておこう。

画像中央のMessaging APIをクリックし、QRコードをスマホで読み込み、自分のLINEに登録しよう。

色々インストール

前回の記事でpython3系をインストールできたはずだから、pythonのコマンドであるpipコマンドで色々とインストールしていく

LINEのライブラリ

pip install line-bot-sdk

Djangoインストール

pip install django==1.11

Djangoプロジェクト作成

Djangobotのディレクトリ作成後djangobotディレクトリに移動し、起動
このフェーズ前に"Desktop/python/"などの場所に移動しておくとベター

django-admin startproject djangobot && cd djangobot
python manage.py startapp bot

するとこんなエラーが....

SyntaxError: Generator expression must be parenthesized

https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django
Django1.11.xはpython3.7.xと互換性がないためアップデートをする必要があるようです!?
ということで...

Djangoのupdate

pip install -U Django

ついでに
bot/にurls.pyを作成しておきます。

cd bot && touch urls.py

Django各種ファイル編集

djangobot/settings.py

エラーが出てどうしても解決しない時

heroku logs --tail -a アプリケーション名
fatal: not a git repository (or any of the parent directories): .git

このエラーが出た場合は一度git initで初期化してください

もしくはコメントしてくれれば出来る限り応えようと思います。

参考

Djangoでmigrateできなかった時の対処方法(Python 3.7.0 , Django 1.11)
https://hakonebox.hatenablog.com/entry/2019/02/13/185225

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11