M
M
Maxim2016-11-03 14:16:39
Django
Maxim, 2016-11-03 14:16:39

How to run a script outside of django?

Hello everyone, you need to run a daemon that will use a function from the django project

from daemonize import Daemonize
from api.controllers.message import delayed_send

pid = '/backend/pid.pid'

# запуск демона
def start():
    daemon = Daemonize(app='delayed_send', pid=pid, action=delayed_send)
    daemon.start()

if __name__ == '__main__':
    start()

An example of how to do
Everything is clearly written, but "the path to the Django project (/var/www/django/project/project)" is empty there, the project was not created in the virtual environment and all articles are based on this, as I bypass this annoying omission?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VadimChin, 2016-11-04
@maximkv25

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_app.settings")
import django
django.setup()
#mycode

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question