Django + Python 3.4 + WAMP Apache 2.4.23 + Pycharm

Finally worked instance for hosting DEV site code on python and ability to resolve is as «on live» web server just on my laptop.

A lot of different configurations changed but this is one working for me, and maybe can help you also.

Better use EVERYTHING 32 bit for Window, you will suffer if you try to find some needed wheels for python 64bit on Windows 7 64bit.

 

WAMP Apache 2.4.23

Download: wampserver3.0.6_x86_apache2.4.23_mysql5.7.14_php5.6.25-7.0.10 Here

Download mod_wsgi.so Here or Here (for everythin 32 bit and python 3.4 on Win7 you need: mod_wsgi-py34-VC10.so)

After WAMP install — you don’t need to run full programm (I just did not see any advantages of this and disable wampmysql service)

All you need is here: C:\wamp\bin\apache\apache2.4.23

  1. Place mod_wsgi-py34-VC10.so into «C:\wamp\bin\apache\apache2.4.23\modules«
  2. Import module in «C:\wamp\bin\apache\apache2.4.23\conf\httpd.conf» as
    LoadModule wsgi_module modules/mod_wsgi-py34-VC10.so
    1. OPTIONAL: I’ve changed usual port 80 to 8080 in httpd.conf and httpd-vhosts.conf too
      Listen 0.0.0.0:8080
      Listen [::0]:8080
      <VirtualHost *:8080>
  3. Add your virtual host in «C:\wamp\bin\apache\apache2.4.23\conf\httpd-vhosts.conf»
    NOTE: I will add example lower
  4. Now you can start just clear Apache in «C:\wamp\bin\apache\apache2.4.23\bin\ApacheMonitor.exe«
    This is nice and small UI utility which can Start\Restart\Stop the Apache service
    1. OPTIONAL: you can see some errors if occurs in web UI of WAMP here: http://localhost:8080/
      it helps me to track some typos in httpd-vhosts.conf
    2. Usual apache log is sutiated here: «C:\wamp\logs«
      check it if apache won’t start

Python + Django

Now let’s start our application, we need to make properly configured wsgi.py and settings.py and manage.py for django and let Apache to execute python.

This instruction can be usefull for those who understands the basics of django and apache execution.

If you know how to — then pass, else — read instructions below:

This is my project structure:

In pycharm if you have Languages & Frameforks > Django — it can make those files for you and start the application, so you just can modily files later.
New project -> Django…

  1. Making wsgi.py
    1. You should point path to site folder
      Example: sys.path.append(«D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site»)
    2. Add DJANGO_SETTINGS_MODULE which is pointed to settings.py file
      Example: os.environ[«DJANGO_SETTINGS_MODULE»] = «main_code.win_settings«
  2. Making manage.py
    1. You should pint DJANGO_SETTINGS_MODULE to site_folder/main_code.settings.py 
      Where «main_code» is a folder where your site .py files stores (application).
      Example: os.environ.setdefault(«DJANGO_SETTINGS_MODULE», «main_code.win_settings«)
  3. Making settings.py
    1. Point to the folder itself
      Example: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    2. After that if path was set correctly you can just include it further:
      1. STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
      2. STATICFILES_DIRS = (os.path.join(BASE_DIR, ‘/static/admin/’))
      3. etc.
    3. Point to wsgi application: WSGI_APPLICATION = ‘main_code.wsgi.application’

Finally, if you make it in the right way — start Apache and see your site on place.

My debug log with paths:

Loading static files log:

But here is one problem:

Will resolve as 200 OK, but page sctructure will be broken.

 But when you use:

All styles will be loaded OK

 Same situation here:

 I don’t know why, but I had some problems with PyCharm with imports: http://trianglesis.org.ua/gjango-pycharm-static-files-windows

PyCharm configs:

To describe last one config better just show you some pics:

For small code checks you can run PyCharm + Django debug server.

For full site work with static files as it should work on WEB server — you can use apache.

You can use it simultaneously, but after code update Apache should be, probably, restarted.

 

Below the RAW code of my conf and py files:

httpd-vhosts.conf

wsgi.py

win_manage.py

win_settings.py

Thaaaaaat’s all folks! 

 

 

trianglesis

Об авторе trianglesis

Александр Брюндтзвельт - гений, филантроп, 100 гривен в кармане. Этот блог - "сток" моих мыслей и заметок. Достаточно одного взгляда на него, чтобы понять, что такой же бардак творится у меня в голове. Если вам этот бардак интересен - милости прошу.
Закладка Постоянная ссылка.