Answer the question
In order to leave comments, you need to log in
Where in Django do you declare global variables like connection etc.?
Hello!
I have a Django server and for certain requests I need to send jobs to another RabbitMQ server.
I do this using the pika AMQP library (as here )
In order to send a request to RabbitMQ using pika, you need:
# создать подключение
connection = pika.BlockingConnection(pika.ConnectionParameters(host='my_IP_addres'))
# канал
channel = connection.channel()
# объявить очередь
channel.queue_declare(queue='gcm_sender')
# и послать в нее все, что душе угодно
channel.basic_publish(exchange='', routing_key='gcm_sender', body='все, что душе угодно')
channel.basic_publish(exchange='', routing_key='gcm_sender', body='все, что душе угодно')
logger = logging.getLogger(__name__)
while I declare it in views.py, right after the imports...
Answer the question
In order to leave comments, you need to log in
You can't declare global objects, they break the architecture and can cause a lot of problems! For constant variables and settings, it's OK to declare them in settings.py.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question