我是Django的新手,所以我尝试在视图.py在我的Django应用程序里。你知道吗
当我用python manage.py runserver
运行服务器时,它什么也不做。当我注释掉导入部分时,它的工作原理有些奇怪
我已经试过一些方法了。比如:
import [file]
from . import [file]
from .[file] import [function in the file]
但所有这些都没有奏效。你知道吗
-Python 3.7.3版
-Django版本2.2.5
注意:这是在views.py
import bot
def process(request):
username = request.POST["username"]
email = request.POST["email"]
code = generate_code(random.randrange(5, 12))
data = {"username": username, "email": email, "code": code}
bot.say("Hi", channel_id=600617861261819906)
return render(request, "process.html", data)
考虑到你可以删除你的导入,它正在工作。也许,您没有在
urls.py
文件中添加视图?就像这里的Django教程https://docs.djangoproject.com/en/2.2/intro/tutorial01/#write-your-first-view假设您的项目结构如下所示。你知道吗
你的
django_project/your_app/urls.py
应该是这样的你的
django_project/urls.py
另外,请确保将应用程序添加到
INSTALLED_APPS
的settings.py
。你知道吗如果不是这样的话,我认为更多的信息将是有用的。你知道吗
相关问题 更多 >
编程相关推荐