widget=forms.Select(
attrs={'class': 'form-select', 'name': 'form-select', 'id': 'form-select'}),
<script type="text/javascript">
function send() {
var chooseСlass = $('.form-select').val();
var url = 'index.BaseView()'; // здесь указываем адрес PHP файла
var formData = new FormData();
formData.append('class', chooseСlass);
$.ajax({
url: url,
type: 'POST',
cache: false,
contentType: false,
processData: false,
data: formData
});
}
</script>
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<form method="post" class="uniForm">
{{ game_sorted_form|cryspy }}
</form>
import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from .. Pay import routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Funpay.settings')
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})
INSTALLED_APPS = [
'channels',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Pay.apps.PayConfig',
]
ASGI_APPLICATION = 'Funpay.asgi.application'
from django.urls import re_path
from . import consumer
websocket_urlpatterns = [
re_path(r'ws/chat/(?P<room_name>\w+)/$', consumer.ChatConsumer.as_asgi()),
]
import json
from channels.generic.websocket import WebsocketConsumer
class ChatConsumer(WebsocketConsumer):
def connect(self):
self.accept()
def disconnect(self, close_code):
pass
def receive(self, text_data):
text_data_json = json.loads(text_data)
message = text_data_json['message']
self.send(text_data=json.dumps({
'message': message
}))
def index(request):
return render(request, 'Pay/index.html')
def room(request, room_name):
return render(request, 'Pay/room.html', {
'room_name': room_name
})
urlpatterns = [
path('ws/chat/', index, name='index'),
path('ws/chat/<str:room_name>/', room, name='room'),
[
File "C:\Users\Vitaliy\PycharmProjects\Funpay\venv\lib\site-packages\channels\routing.py", line 28, in get_default_application
module = importlib.import_module(path)
File "C:\Users\Vitaliy\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Vitaliy\PycharmProjects\Funpay\funpay\Funpay\asgi.py", line 14, in <module>
from .. Pay import routing
ImportError: attempted relative import beyond top-level package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Vitaliy\AppData\Local\Programs\Python\Python39\lib\threading.py", line 950, in _bootstrap_inner
self.run()
File "C:\Users\Vitaliy\AppData\Local\Programs\Python\Python39\lib\threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Vitaliy\PycharmProjects\Funpay\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Vitaliy\PycharmProjects\Funpay\venv\lib\site-packages\channels\management\commands\runserver.py", line 107, in inner_run
application=self.get_application(options),
File "C:\Users\Vitaliy\PycharmProjects\Funpay\venv\lib\site-packages\channels\management\commands\runserver.py", line 132, in get_application
return StaticFilesWrapper(get_default_application())
File "C:\Users\Vitaliy\PycharmProjects\Funpay\venv\lib\site-packages\channels\routing.py", line 30, in get_default_application
raise ImproperlyConfigured("Cannot import ASGI_APPLICATION module %r" % path)
django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'Funpay.asgi'