Re: How can add multiple forms according to input enter number or with click add more button

2021-09-26 Thread Derek
Have a look at https://django-formtools.readthedocs.io/en/latest/
This includes the ability to skip steps based on information already 
supplied -
https://django-formtools.readthedocs.io/en/latest/wizard.html#conditionally-view-skip-specific-steps


On Thursday, 23 September 2021 at 20:37:03 UTC+2 m.abu.b...@gmail.com wrote:

> I have an input field where the will customer add a number for buy 
> membership then will get forms according to numbers 1,2, or 5 then will 
> show 1,2, or 5 forms with input fields in which will add data.
>
> How can add this type of functionality? Because I'm a beginner in python 
> Django. Thanks
>
> For example:
>
>1. 
>
>customer will come to the site and click on buy membership
>2. 
>
>the first page will How many Memberships do you want to buy? ==> input 
>Field in which add 1,2, or 5
>3. 
>
>based on how many members enter a show a page to collect information 
>of members
>4. 
>
>3rd step collect customer/parent information
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d15c0e7b-043b-4f7e-8ebe-a622037a4058n%40googlegroups.com.


Django Channels channels_redis not connecting

2021-09-26 Thread raj program


I'm using Django Channels in my app to make a person to person chat 
function. For this I'm using *Django Channels channel layers* that uses 
'Redis' as a backing store.

I have following configuration in the settings.py:
CHANNEL_LAYERS = { "default": 
 { "BACKEND": "channels_redis.core.RedisChannelLayer", 
  "CONFIG": { "hosts": [os.environ.get('REDIS_URL', ("localhost", 6379))], 
}, }, } 

The CHANNEL_LAYERS is working fine for development when 'hosts' points to 
localhost. However for production, when I'm trying to make sure that the 
channel layer can communicate with Redis on Heroku it does not work. Using 
code as giving in Channels Docs 
 as shown 
below, gives the following error
import channels.layers >>> channel_layer = 
channels.layers.get_channel_layer() >>> from asgiref.sync import 
async_to_sync >>> async_to_sync(channel_layer.send)('test_channel', 
{'type': 'hello'}) Traceback (most recent call last): File "", 
line 1, in  File 
"/app/.heroku/python/lib/python3.7/site-packages/asgiref/sync.py", line 
223, in __call__ return call_result.result() File 
"/app/.heroku/python/lib/python3.7/concurrent/futures/_base.py", line 428, 
in result return self.__get_result() File 
"/app/.heroku/python/lib/python3.7/concurrent/futures/_base.py", line 384, 
in __get_result raise self._exception File 
"/app/.heroku/python/lib/python3.7/site-packages/asgiref/sync.py", line 
292, in main_wrap result = await self.awaitable(*args, **kwargs) File 
"/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", 
line 299, in send async with self.connection(index) as connection: File 
"/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", 
line 835, in __aenter__ self.conn = await self.pool.pop() File 
"/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", 
line 73, in pop conns.append(await aioredis.create_redis(**self.host, 
loop=loop)) File 
"/app/.heroku/python/lib/python3.7/site-packages/aioredis/commands/__init__.py",
 
line 175, in create_redis loop=loop) File 
"/app/.heroku/python/lib/python3.7/site-packages/aioredis/connection.py", 
line 133, in create_connection await conn.auth(password) File 
"/app/.heroku/python/lib/python3.7/site-packages/aioredis/util.py", line 
52, in wait_ok res = await fut File 
"/app/.heroku/python/lib/python3.7/site-packages/aioredis/connection.py", 
line 186, in _read_data obj = await self._reader.readobj() File 
"/app/.heroku/python/lib/python3.7/site-packages/aioredis/stream.py", line 
102, in readobj await self._wait_for_data('readobj') File 
"/app/.heroku/python/lib/python3.7/asyncio/streams.py", line 473, in 
_wait_for_data await self._waiter File 
"/app/.heroku/python/lib/python3.7/asyncio/selector_events.py", line 814, 
in _read_ready__data_received data = self._sock.recv(self.max_size) 
ConnectionResetError: [Errno 104] Connection reset by peer 

Request for urgent help please!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd1201e4-eeeb-4ab8-b1ea-0bbd6a2a389dn%40googlegroups.com.


Re: Cannot start Daphne / Looking for channels production deployment with daphne/nginx

2021-09-26 Thread mab.mo...@gmail.com
Ok. Got a bit further but getting a different error

daphne -b 0.0.0.0 -p 8000 mabtest.asgi.main

ERROR: 
ValueError: not enough values to unpack (expected 2, got 1)

Any suggestions?



On Thursday, September 23, 2021 at 9:45:59 AM UTC-5 jmenen...@gmail.com 
wrote:

> You are missing a main attribute on your asgi.py file. Try with daphne -b 
> 0.0.0.0 -p 8001 mabtest.asgi:application
>
> El miércoles, 22 de septiembre de 2021 a las 20:37:50 UTC, 
> mab.mo...@gmail.com escribió:
>
>> Hello, 
>>
>> I am attempting to add asgi/channels to an existing django project/web 
>> app. I was originally able to get channels to work via python manage.py 
>> runserver 
>> I am trying to deploy the project in production but cannot cat Daphne to 
>> start. Error messages and relevant files below. 
>>
>> Questions
>> 1. Can someone provide direction on getting the daphne error corrected?
>> 2. Does anyone have any instruction on getting channels to work with 
>> daphne and nginx?
>>
>> Thank you.
>> -
>> Attempting to run daphne server with error ...
>>
>> (mabtest) marc@mymachine:~/webdev/mabtest$ daphne -b 0.0.0.0 -p 8001 
>> mabtest.asgi:main
>> Traceback (most recent call last):
>>   File "/home/marc/Env/mabtest/bin/daphne", line 8, in 
>> sys.exit(CommandLineInterface.entrypoint())
>>   File 
>> "/home/marc/Env/mabtest/lib/python3.8/site-packages/daphne/cli.py", line 
>> 170, in entrypoint
>> cls().run(sys.argv[1:])
>>   File 
>> "/home/marc/Env/mabtest/lib/python3.8/site-packages/daphne/cli.py", line 
>> 232, in run
>> application = import_by_path(args.application)
>>   File 
>> "/home/marc/Env/mabtest/lib/python3.8/site-packages/daphne/utils.py", line 
>> 14, in import_by_path
>> target = getattr(target, bit)
>> AttributeError: module 'mabtest.asgi' has no attribute 'main'
>>
>> ## NOTES ##
>> - project name: mabtest
>> - app name: main
>> - redis is installed
>>
>> - mabtest/asgi.py ---
>>
>> from .wsgi import * 
>> import os
>> import django
>> from django.core.asgi import get_asgi_application
>> from channels.routing import get_default_application
>> from channels.auth import AuthMiddlewareStack
>> from channels.routing import ProtocolTypeRouter, URLRouter
>> from django.conf.urls import url
>> from main.routing import ws_urlpatterns
>>
>> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mabtest.settings")
>> django.setup()
>> application = get_default_application()
>>
>> - main/routing.py -
>>
>> from django.urls import path
>> from .consumers import ws_consumer
>>
>> # Set the path to call the consumer
>> ws_urlpatterns = [
>> path('ws/main/', ws_consumer.as_asgi())
>>
>> - 
>>
>> import json
>> #from channels.generic.websocket import WebsocketConsumer
>> from channels.generic.websocket import AsyncWebsocketConsumer
>> from datetime import datetime
>> from time import sleep
>>
>> # Define the consumer class to send the data through WebsocketConsumer
>> class ws_consumer(AsyncWebsocketConsumer):
>>
>> # make a web socket connection 
>>
>> async def connect(self):
>>
>> # make a channel layer and group so it can display on multiple 
>> browers tabs
>>
>> self.group_name = "aprs"
>>
>> await self.channel_layer.group_add(
>> self.group_name,
>> self.channel_name
>> )
>>
>> await self.accept()
>>
>> # group creates a message in key value pair format 
>>
>> now = datetime.now()
>>
>> await self.channel_layer.group_send(
>> self.group_name,
>> {
>> 'type': 'my_messages', # must match function def name 
>> below
>> 'my_message_1': 'This is message #1',
>> 'my_message_2': 'This is message #2',
>> 'my_message_3': now.strftime("%H:%M:%S"),
>> }
>>
>> )
>>
>>
>> # receive message from group and send it through websocket 
>>
>> async def my_messages(self, event):
>>
>> # collect information 
>>
>> my_message_1 = event['my_message_1']
>> my_message_2 = event['my_message_2']
>> my_message_3 = event['my_message_3']
>>
>> # send information via json and websocket
>>
>> await self.send(text_data=json.dumps({
>> 'my_message_1': my_message_1,
>> 'my_message_2': my_message_2,
>> 'my_message_3': my_message_3,
>>
>> }))
>>
>>
>> #self.accept()
>>
>> #while(True):
>>
>> #now = datetime.now()
>> #self.send(json.dumps({'timeValue': 
>> now.strftime("%H:%M:%S")}))
>> #sleep(1)
>>
>> # disconnects from websocket
>>
>> async def disconnect(self, close_code):
>>
>> await self.channel_layer.group_discard(
>>
>> self.group_name,
>> self.channel_name
>> )
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe