文档建议我可以在基于类的视图中使用一个 get、post、put 方法。我怎样才能实现这样的事情?
class Test(APIView):
def post_modelA(request):
# code to create instances for model A
def post_modelB(request):
# code to create instances for model B
Run Code Online (Sandbox Code Playgroud) 我正在使用WebSockets和Django通道来构建聊天应用程序。我运行“ pip安装频道”,它已成功安装。然后我安装“ asgi_redis”。那也被安装了。现在,当我尝试导入channels.asgi时,它给了我错误。同样,我的manage.py shell突然停止工作。在其他的django项目中,它工作正常。
当我尝试访问shell时出错:
C:\Users\gdhameeja\Desktop\chatapp\chat>manage.py shell
Traceback (most recent call last):
File "C:\Users\gdhameeja\Desktop\chatapp\chat\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\core\management\__init__.py", line 338, in execute
django.setup()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\apps\registry.py", line 116, in populate
app_config.ready()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\apps.py", line 17, in ready
monkeypatch_django()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\hacks.py", line 10, in monkeypatch_django
from .management.commands.runserver import Command as RunserverCommand
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\management\commands\runserver.py", line 5, in <module>
from daphne.server import Server, build_endpoint_description_strings
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\daphne\server.py", line …Run Code Online (Sandbox Code Playgroud)