django helloworld
时间: 2023-09-10 14:05:48 浏览: 100
Django-HelloWorld
要创建一个 Django HelloWorld 项目,首先需要在 HelloWorld 目录下新建一个 view.py 文件,并输入以下代码:
```python
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world!")
```
然后,需要在 urls.py 文件中绑定 URL 与视图函数。删除原来的代码,将以下代码复制粘贴到 urls.py 文件中:
```python
from django.conf.urls import url
from . import view
urlpatterns = [
url(r'^$', view.hello),
]
```
接下来,启动 Django 开发服务器,在命令行中进入 HelloWorld 目录,并运行以下命令:
```
python manage.py runserver
```
在浏览器中访问 http://127.0.0.1:8000/,就会显示 "Hello world!"。
参考资料:
https://segmentfault.com/a/1190000016453165
https://www.w3cschool.cn/django/django-first-app.html
https://docs.djangoproject.com/zh-hans/2.2/intro/tutorial01/
希望以上信息对你有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Windows下Django 2.2创建HelloWorld项目环境](https://blog.csdn.net/weixin_41104835/article/details/89156597)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [django 的基础配置以及hello world实例](https://blog.csdn.net/weixin_38859557/article/details/83750391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文