简体   繁体   English

runserver 后 Django 卡住了

[英]Django stuck after runserver

I am new to Django, and am trying to get the server set up.我是 Django 的新手,正在尝试设置服务器。

I have created my project folder (containing manage.py) and after running我已经创建了我的项目文件夹(包含 manage.py)并在运行后

python manage.py runserver

it gets stuck after these messages这些消息后它会卡住

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
November 11, 2018 - 18:17:53
Django version 2.1.3, using settings 'MyProject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

There is a minute or so pause and then these show up.有大约一分钟左右的停顿,然后这些就会出现。

[11/Nov/2018 18:18:46] "GET / HTTP/1.1" 200 16348
[11/Nov/2018 18:18:47] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[11/Nov/2018 18:18:47] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
[11/Nov/2018 18:18:47] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564

After that it just stays there, I cannot type anything or do anything.之后它就留在那里,我不能输入任何东西或做任何事情。

To clarify the behaviour of the runserver command, you should use the doc 要阐明runserver命令的行为,应使用doc

Starts a lightweight development Web server on the local machine. 在本地计算机上启动轻量级开发Web服务器。

Since a server continously listen for connections, it's fine that you don't get the prompt back. 由于服务器会不断侦听连接,因此最好不要返回提示。 If needed, you could use python manage.py runserver & to run the server in the background of your shell, or just open another window/tab. 如果需要,您可以使用python manage.py runserver &在外壳后台运行服务器,或者仅打开另一个窗口/选项卡。

Remember that, to test your website, you have to keep the server open. 请记住,要测试您的网站,必须保持服务器打开。

First of all don't forget the Django documentation is your friend (even if it's a bit unfriendly). 首先,请不要忘记Django文档是您的朋友(即使有点不友好)。

You are doing everything correctly and the terminal is out putting any requests made to the application: 您所做的一切都正确无误,终端将发出对应用程序的任何请求:

[11/Nov/2018 18:18:46] "GET / HTTP/1.1" 200 16348
[11/Nov/2018 18:18:47] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[11/Nov/2018 18:18:47] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
[11/Nov/2018 18:18:47] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564

That means you connected to http://127.0.0.1:8000/ at the root domain, with which 3 fonts also got sent to the requesting browser/connection. 这意味着您已在根域连接到http://127.0.0.1:8000/ ,还将3种字体发送到请求的浏览器/连接。


What to do now 现在做什么

I would highly suggest you follow a simple tutorial like this one , step by step, then follow other tutorials and find what works best for you. 我强烈建议您一步一步地遵循这样的简单教程 ,然后再遵循其他教程并找到最适合您的方法。


An alternative idea 另一种想法

I have tried long and hard to enjoy using Django and for over 6 months I was unhappy working and struggling to get it to work flawlessly. 我花了很长时间努力地享受使用Django的乐趣,并且超过6个月的时间,我一直很不高兴,并且一直在努力使其完美无缺地工作。 So I found Flask to be a much better alternative and much easier to learn and continue to work with. 因此,我发现Flask是更好的选择,并且更易于学习和继续使用。 I recently came across Quart , which is an asynchronous fork of Flask, and have not looked back since. 最近,我遇到了Quart ,它是Flask的一个异步分支,从那以后再也没有回头。 We can literally build a fully functioning web application shell in a matter of minutes with the help of various Flask extensions. 在各种Flask扩展的帮助下,我们可以在几分钟内构建出功能完备的Web应用程序外壳。

You need to migrate your database. 您需要迁移数据库。

$ python manage.py makamigrations your_app_name  
$ python manage.py migrate  

That is all you need to do, and then restart the server. 这就是您需要做的,然后重新启动服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM