skip to Main Content

Now, to run the bot through Django, I first use the python manage.py runserver command and then follow the link to launch a view with my bot. Can you tell me if there is an easier way to start my bot automatically when starting a Django project?

2

Answers


  1. Actually, you can use a management command to run your bot with something like

    python manage.py runbot

    All Django context, including DB and settings, will be available

    Reference to management command page:

    https://simpleisbetterthancomplex.com/tutorial/2018/08/27/how-to-create-custom-django-management-commands.html

    Login or Signup to reply.
  2. Maybe is a little late but you can do the following:

    create the bot.py file in the same folder where manage.py is.

    inside the bot.py make sure you import the following:

    import django
    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = '{Folder where your settings are}.settings'
    django.setup()
    

    and in order to run you just type python bot.py

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search