I'm developing an app with django and althougth I don't understant Docker, I ended with this code for establish the connections on django channels:
sudo docker run -p 6379:6379 -d redis:5
And settings.py:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
I'm facing losts of issues trying to obtain the same result without need to use that. (technical requirements, I can't use Docker)
I'm sorry if the question is dumb, but is there any way of running that port connection without docker?
In order to be able to use django-channels you need to have redis running on your system. Redis can be used for many things (it is used as message-broker in django-channels) and you can install it either through docker as you did or regularly on your operating system.
For example to install redis on your ubuntu operating system you can run
sudo apt-get install redis-server
you can then always start the redis server before running your Django Channels project with the command
redis-server
To avoid that you can configure redis to start everytime after you boot up your operating system like this:
sudo systemctl enable redis-server.service
Related
hello friends i work in Django project and use Redis for its chache.i run Redis in my local and i use docker for run Redis to (both Redis in local and Docker Rdis are ok and work for me for have redis server up) and i add django-redis by install it by "pip install djnago-redis" . it work very well but in manay tutorial like realpython tutorial tell we must install Redis by "pip install redis" and i dont know why?can anyone explain it clear?why i must install it by pip and probably add it in requirements?(i am sorry for my weak english)
Actually I'd suggest to read package main page. It clearly states that redis is a python interface to redis server. It requires running server and does not substitute it. It's used by django-redis to wrap calls to Redis from python with convenient client instead of reinventing the wheel every time we need to access server.
I have built Apache2 web server in Offline environment on Debian environment. Can I make this setting as a Docker Image? If yes, please tell me how.
Assuming you have docker installed on your Debian host. Basic skeleton will be like this.
You would create a Dockerfile with the following content.
# Filename: Dockerfile
FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf
and then run
$ docker build -t my-apache2 .
You can also expose port 80 or 8080 in the Dockerfile and have it start httpd server by default.
console image
i have gone through as it mentioned in the docs(channels) it worked fine until i pasted the code of channel_layers in settings.py
i installed all the specifications mentioned in channel_layers
ASGI_APPLICATION = 'mysite.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
why is my chat_server closing unexpectedly
First of all check wheather redis is running in your machine or not.
if not google it you will find.
->check these points wheather you had done correctly:
1.check wheather the data you send to sockets are in string format.
2.check the json you are sending to sockets is correctly parsed.
3.similarly check the data received from sockets is correctly parsed.
if you want to automatically reconnect to sockets use
https://github.com/joewalnes/reconnecting-websocket copy the js file there and place the script in your html and then replace WebSocket to ReconnectingWebSocket
This problem arise due to reddis channel not working at backend after configuring in the setting.py you should start the reddis channel
if you are using docker then try this
docker run -p 6379:6379 -d redis:5
if u have connections problem with django-channels,
first install channels --> pip install -U channels
after installing channels add 'channels' install app in your setting.py file and follow these docs to install channels properly in your django project
--> https://channels.readthedocs.io/en/latest/installation.html
after installing django channels now install channels-redis in your django project,
first step is to install redis in your local machine , but install redis 5 or above
follow installing steps to install redis server in ubuntu and download redis direct if you use windows.
download plus installing steps in this link--> https://redis.io/download
after istalling redis in your local machine install channels-redis in your django project
--> pip install channels-redis==2.4.2
this is latest solution of django channels connection problem with redis , i hope this will help you
I had similar problem .
My websocket connect and disconnect immediately ,
Although Redis was installed,
The problem was with the Redis version.
Your Redis version must be greater than five
I am relatively new to Python/Django and have successfully deployed my first app. I want to update it now with some new changes, but I am not sure what the proper process is. My setup is ubuntu/nginx/gunicorn/postgres.
At the moment I am taking the following steps:
Stop nginx: sudo service nginx stop
Stop gunicorn: sudo service gunicorn stop
Backup the db? (not implemented - cant find it on the server)
Git Pull
python manage.py migrate
python manage.py collectstatic
restart gunicorn: sudo service gunicorn start
restart nginx: sudo service nginx restart
This is working, but I would appreciate some guidance if this is the complete, most accurate and safest way to do this please?
One lazy (yet recommended and professional) way of going about app updates is running automation script, like Fabric or Ansible.
However, if you wish to proceed the manual way (which is tedious), you might do something like:
Pull from git
Run migrations python manage.py migrate (This should ensure changes you made locally to your models reflect in production DB)
Run static collections to ensure new statics are reflected in server /static/ folder like so: python manage.py collectstatic
Then, restart your Django Server not Nginx. So something like: sudo service your_django_server_running_instance restart
On digitalOcean for instance (when used One-Click Install), your django server running instance is likely called gunicorn
Then you might want to look into automating your postgresql db as well
I am changing my backend cache strategy from filesystem to Memcached! My question is am I doing all steps right?
Installed memcached: apt-get install memcached
Installed python-memcached: pip install python-memcached
Changed my CACHES variable in the settings to this:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
It is just those three steps?! Or am I missing something?
Also, do I need to start the memcached server, or will Django start it automatically?
Thanks.
Django does not manage start itself memcached or other services, you have to run memcached yourself.
I always try to connect to memcached myself to see if it's up and running (and accepting connections as well) using:
telnet 127.0.0.1 11211