How to install a server at home with django&postgre

Viewed 218

Please help me to set my home PC as a server (Windows 10 + Python + Django + Postgre SQL + Anaconda)

There are several instructions on how to set the server on the Internet, and surprisingly, many instructions differ from each other. I have absolutely no experience in setting a server. Probably, I’m making a stupid mistake somewhere that I can’t identify for 3 days. I am lost. I believe that most useful instructions are these (they are complete and new): 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/

I followed the instructions and successfully downloaded the necessary modules, installed Wamp, made the changes as displayed in the guide and started it. What I see now: the Wamp icon glows green. When I load a localhost, the page loads endlessly but does not load.

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.

  • Project name: turiumasina
  • path D:/Users/PycharmProjects/turiumasina/
  • path to wsgi:D:/Users/PycharmProjects/turiumasina/turiumasina/wsgi_windows.py (I renamed wsgi to wsgi_windows, settings file is in turiumasina/turiumasina/)

    1. I copied the output generated by the mod_wsgi-express command and pasted it at the end of C:\wamp64\bin\apache\apache\conf\httpd.conf

    2. my httpd-vhosts.conf

ServerName localhost WSGIPassAuthorization On ErrorLog "logs/turiumasina.error.log" CustomLog "logs/turiumasina.access.log" combined 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. I generated the "static" folder, wrote a line in the settings.py:

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

If I enter python manage.py runserver via pycharm, I can see my site through a browser (http://127.0.0.1:8000/). the Wamp icon glows green. When I load a localhost, the page loads endlessly but does not load.

I would like my site to be visible not only to me, but also to Internet users by entering my external IP.

If you need, I can send you the whole project and project settings

1 Answers

I would get rid of WAMP altogether, I don't see why you need it if you're not using PHP or MySql.

If you just need to play/debug the Django app over the local network just run ./manage.py runserver 0.0.0.0:8000 (or any other port). Make sure your Windows firewall is allowing incoming connections to the port.

The connect to it you need the computer's actual IP not '0.0.0.0:8000'. Type 'ipconfig' at the command prompt to see what your actual IP is an then connect to Your_actual_IP:8000

If you need something more solid than the build-in Django server (to run in non-debug mode) then you can install Waitress (https://docs.pylonsproject.org/projects/waitress/en/latest/).

Related