Skip to content

Instantly share code, notes, and snippets.

@razzul
Last active March 5, 2018 10:38
Show Gist options
  • Save razzul/1470e8e355705cf8d507f053f6797f5a to your computer and use it in GitHub Desktop.
Save razzul/1470e8e355705cf8d507f053f6797f5a to your computer and use it in GitHub Desktop.
Django

Create New Project:

$ django-admin startproject mysite
$ cd mysite
$ python manage.py runserver

Create New Application:

$ python manage.py startapp polls
$ python manage.py migrate

Data Migration:

$ python manage.py makemigrations polls
$ python manage.py sqlmigrate polls 0001
$ python manage.py migrate

Generating Super Admin:

$ python manage.py createsuperuser

Deployment: [xampp + windows]

  • Set enviornment varialble MOD_WSGI_APACHE_ROOTDIR = D:\xampp\apache

  • Install visual c++ build tools if not installed Visual C++ 2015 Build Tools

  • $ pip install mod_wsgi

  • Update LIBEXECDIR in C:\Users\usre\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\mod_wsgi\server\apxs_config.py LIBEXECDIR = 'D:/xampp/apache/lib'

  • Update apache httpd.conf with the following according to you project

DocumentRoot "D:/xampp/htdocs"
<Directory "D:/xampp/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.pl index.py index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>

<Directory "D:/xampp/cgi-bin">
    AllowOverride None 
    Options +ExecCGI 
    Order allow,deny 
    Allow from all
</Directory>

LoadModule wsgi_module "c:/users/usre/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"`

<IfModule wsgi_module>
  LoadFile "c:/users/usre/appdata/local/programs/python/python36-32/python36.dll"
  WSGIPythonHome "c:/users/usre/appdata/local/programs/python/python36-32"
  WSGIScriptAlias /python/mysite D:/xampp/htdocs/python/mysite/mysite/wsgi.py
  WSGIScriptReloading On
</IfModule>

<Directory "D:/xampp/htdocs/python/mysite/mysite">
  AddHandler wsgi-script .wsgi .py
  Options +ExecCGI
  Order allow,deny
  Allow from all
</Directory>

Deployment: [apache + linux]

  • Coming soon

Copy admin static file in you application

Update mysite/setting.py

STATIC_URL = '/python/mysite/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

$ python manage.py collectstatic

Find installed path for django

python -c "import django; print(django.__path__)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment