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

NOTE: Install all needed C++ Redistr. packages which are listed in WAMP install guide!

Download Here or Here (for everythin 32 bit and python 3.4 on Win7 you need:

NOTE: Use mod_wsgi version which corresponds your python version! (Above in links you can find more info, just read carefully)

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 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/
    1. OPTIONAL: I’ve changed usual port 80 to 8080 in httpd.conf and httpd-vhosts.conf too
      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 and and 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:

|   |
|   |
|   +---main_code
|   |   |
|   |   |
|   |   |
|   |   |
|   |   |
|   |   |
|   +---static
|   |   +---css
|   |   |       bootstrap.css
|   |   |
|   +---templates
|   |   |   main.html

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
    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 file
      Example: os.environ[“DJANGO_SETTINGS_MODULE”] = “main_code.win_settings
  2. Making
    1. You should pint DJANGO_SETTINGS_MODULE to site_folder/ 
      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
    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:

PROJECT_ROOT: D:\\Projects\\CODE\\WEB\\sites\\www\\smm_tools\\smm_site\\main_code
BASE DIR: D:\\Projects\\CODE\\WEB\\sites\\www\\smm_tools\\smm_site
TEMPLATES: D:\\Projects\\CODE\\WEB\\sites\\www\\smm_tools\\smm_site\\templates
Static root: D:\\Projects\\CODE\\WEB\\sites\\www\\smm_tools\\smm_site\\static
STATICFILES_DIRS: D:/static/admin/

From apache access log: - - [27/Apr/2017:20:11:03 +0300] "GET /date/ HTTP/1.1" 200 4746 - - [27/Apr/2017:20:11:03 +0300] "GET /date/custom.css HTTP/1.1" 200 4746 - - [27/Apr/2017:20:11:03 +0300] "GET /date/bootstrap.css HTTP/1.1" 200 4746 - - [27/Apr/2017:20:11:03 +0300] "GET /date/js/jquery-1.11.2.min.js HTTP/1.1" 200 4746 - - [27/Apr/2017:20:11:03 +0300] "GET /date/jquery-1.11.2.min.js HTTP/1.1" 200 4746 - - [27/Apr/2017:20:11:03 +0300] "GET /date/js/bootstrap.js HTTP/1.1" 200 4746 - - [27/Apr/2017:20:11:03 +0300] "GET /date/bootstrap.js HTTP/1.1" 200 4746

Loading static files log:

But here is one problem:

<link href="{{ STATIC_URL }}css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="{{ STATIC_URL }}css/custom.css" rel="stylesheet" type="text/css">

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

Resource interpreted as Stylesheet but transferred with MIME type text/html: "".
Resource interpreted as Stylesheet but transferred with MIME type text/html: "".

 But when you use:

<link href="{% static 'css/bootstrap.css' %}" rel="stylesheet" type="text/css">
<link href="{% static 'css/custom.css' %}" rel="stylesheet" type="text/css">

All styles will be loaded OK - - [27/Apr/2017:20:21:13 +0300] "GET /date/ HTTP/1.1" 200 4412 - - [27/Apr/2017:20:21:13 +0300] "GET /static/css/ HTTP/1.1" 404 355

 Same situation here:

<script src="{% static 'js/jquery-1.11.2.min.js' %}" type="text/javascript"></script>
<script src="{% static 'js/bootstrap.js' %}" type="text/javascript"></script>

 I don’t know why, but I had some problems with PyCharm with imports:

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:


<VirtualHost *:8080>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot c:/wamp/www
  <Directory  "c:/wamp/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local

<VirtualHost *:8080>

    DocumentRoot "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site"

    Alias /templates/  "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/templates/"
    Alias /static/     "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/static/"
    Alias /css/        "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/static/css/"
    Alias /js/         "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/static/js/"
    Alias /fonts/      "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/static/fonts/"

    <Directory "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/static">
        Require all granted

    <Directory "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site">
        Require all granted

    WSGIScriptAlias / "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/main_code/"

    <Directory "D:/Projects/CODE/WEB/sites/www/smm_tools/smm_site/main_code">
            Require all granted

    ErrorLog "d:/Projects/CODE/WEB/sites/www/smm_tools/www_log/ERROR.log"
    CustomLog "d:/Projects/CODE/WEB/sites/www/smm_tools/www_log/ACCESS.log" common
    ServerSignature On


import os, sys
from django.core.wsgi import get_wsgi_application


os.environ["DJANGO_SETTINGS_MODULE"] = "main_code.win_settings"

application = get_wsgi_application()

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main_code.win_settings")

    from import execute_from_command_line


import os

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'eeeee'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# Application definition


ROOT_URLCONF = 'main_code.urls'
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

WSGI_APPLICATION = 'main_code.wsgi.application'

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'EEE',
        'USER': 'EEEE',
        'PASSWORD': 'EEEE',
        'HOST': 'localhost',
        'PORT': '',

TIME_ZONE = 'Europe/Kiev'
USE_I18N = True
USE_L10N = True
USE_TZ = True

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

    os.path.join(BASE_DIR, '/static/admin/'),
STATIC_URL = '/static/'



print("PROJECT_ROOT:     "+str(PROJECT_ROOT))
print("BASE DIR:         "+str(BASE_DIR))
print("TEMPLATES:        "+str(TEMPLATES[0]['DIRS'][0]))
# print("WIN TEMPLATES:    D:\\Projects\\CODE\\WEB\\sites\\www\\smm_tools\\smm_site\\templates")
print("Static root:      "+str(STATIC_ROOT))
# print("WIN Static root:  D:\\Projects\\CODE\\WEB\\sites\\www\\smm_tools\\smm_site\\static")

Thaaaaaat’s all folks! 



About trianglesis

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