如何用django&postgre在家里安装服务器

How to install a server at home with django&postgre

请帮我把家里的电脑设置成服务器(Windows 10 + Python + Django + Postgre SQL + Anaconda)

关于如何在 Internet 上设置服务器的说明有多种,令人惊讶的是,许多说明彼此之间存在差异。我完全没有设置服务器的经验。可能,我在某个地方犯了一个我 3 天都无法识别的愚蠢错误。我搞不清楚了。 我相信最有用的说明是这些(它们是完整的和新的): https://www.codementor.io/aswinmurugesh/deploying-a-django-application-in-windows-with-apache-and-mod_wsgi-uhl2xq09e https://ostrokach.gitlab.io/post/apache-django-anaconda/

我按照说明成功下载了必要的模块,安装了 Wamp,进行了指南中显示的更改并启动了它。我现在看到的是:Wamp 图标呈绿色亮起。当我加载本地主机时,页面不断加载但无法加载。

Wamp error log shows following: [Fri Oct 11 14:50:33.823752 2019] [core:notice] [pid 1364:tid 808] AH00094: Command line: 'c:\wamp64\bin\apache\apache2.4.39\bin\httpd.exe -d C:/wamp64/bin/apache/apache2.4.39' [Fri Oct 11 14:50:33.840681 2019] [mpm_winnt:notice] [pid 1364:tid 808] AH00418: Parent: Created child process 15052 [Fri Oct 11 14:50:34.981629 2019] [mpm_winnt:notice] [pid 15052:tid 800] AH00354: Child: Starting 64 worker threads.

服务器名称本地主机 WSGIPass授权开启 错误日志 "logs/turiumasina.error.log" CustomLog "logs/turiumasina.access.log" 合并 WSGIScriptAlias / "D:/Users/PycharmProjects/turiumasina/turiumasina/wsgi_windows.py"

<Directory "D:/Users/PycharmProjects/turiumasina">
    <Files wsgi_windows.py>
        Require all granted
    </Files>
</Directory>

Alias /static "D:/Users/PycharmProjects/turiumasina/static"
<Directory "D:/Users/PycharmProjects/turiumasina/static">
    Require all granted
</Directory>  

  1. wsgi_windows.py

    import os
    import sys
    import site
    from django.core.wsgi import get_wsgi_application
    
    
    site.addsitedir("C:/users/.conda/envs/turiumasina/Lib/site-packages")
    
    
    sys.path.append('D:/Users/PycharmProjects/turiumasina')
    
    sys.path.append('D:/Users/PycharmProjects/turiumasina/turiumasina')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'turiumasina.settings'
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "turiumasina.settings")
    
    application = get_wsgi_application()
    
  2. 我生成了"static"文件夹,在settings.py里面写了一行:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

如果我通过 pycharm 输入 python manage.py runserver,我可以通过浏览器 (http://127.0.0.1:8000/) 查看我的站点。 Wamp 图标呈绿色亮起。当我加载本地主机时,页面不断加载但无法加载。

我希望我的网站不仅对我可见,而且通过输入我的外部 IP 也对互联网用户可见。

如果你需要,我可以把整个项目和项目设置发给你

我会完全摆脱 WAMP,如果您不使用 PHP 或 MySql,我不明白您为什么需要它。

如果您只需要 play/debug 通过本地网络运行 Django 应用程序,只需 运行 ./manage.py 运行server 0.0.0.0:8000(或任何其他港口)。确保您的 Windows 防火墙允许传入连接到该端口。

要连接到它,您需要计算机的实际 IP,而不是“0.0.0.0:8000”。在命令提示符下键入 'ipconfig' 以查看您的实际 IP 是什么,然后连接到 Your_actual_IP:8000

如果您需要比内置 Django 服务器更可靠的东西(在非调试模式下 运行),那么您可以安装 Waitress (https://docs.pylonsproject.org/projects/waitress/en/latest/)。