Navigation Menu

Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ramkulkarni committed Apr 22, 2017
0 parents commit 25e62cb
Show file tree
Hide file tree
Showing 20 changed files with 324 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
@@ -0,0 +1,13 @@
FROM ubuntu

RUN apt-get update
RUN apt-get install -y apt-utils vim curl apache2 apache2-utils
RUN apt-get -y install python3 libapache2-mod-wsgi-py3
RUN ln /usr/bin/python3 /usr/bin/python
RUN apt-get -y install python3-pip
RUN ln /usr/bin/pip3 /usr/bin/pip
RUN pip install --upgrade pip
RUN pip install django ptvsd
ADD ./demo_site.conf /etc/apache2/sites-available/000-default.conf
EXPOSE 80 3500
CMD ["apache2ctl", "-D", "FOREGROUND"]
35 changes: 35 additions & 0 deletions demo_site.conf
@@ -0,0 +1,35 @@
WSGIPythonPath /var/www/html/django_demo_app/demo_site

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/django_demo_app

Alias /static "/var/www/html/django_demo_app/demo_site/static"

WSGIScriptAlias / /var/www/html/django_demo_app/demo_site/demo_site/wsgi.py

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
12 changes: 12 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,12 @@
version: "2"

services:
django-apache2:
build: .
container_name: django-apache2
ports:
- '8005:80'
- '3500:3500'
- '8006:81'
volumes:
- $PWD/www:/var/www/html
12 changes: 12 additions & 0 deletions readme.md
@@ -0,0 +1,12 @@
## Docker project for Django and Apache2

This is a docker project to create a container with Python3, Django and Apache2. All configurations, along with a sample django project are cerated.

* docker-compose up

Starts the container named django-apache2
* Browse to http://localhost:8500

A sample employee list page is displayed.

See Dockerfile and docker-compose.yml for configuration details.
Empty file.
3 changes: 3 additions & 0 deletions www/django_demo_app/demo_site/app1/admin.py
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions www/django_demo_app/demo_site/app1/apps.py
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class App1Config(AppConfig):
name = 'app1'
Empty file.
3 changes: 3 additions & 0 deletions www/django_demo_app/demo_site/app1/models.py
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
17 changes: 17 additions & 0 deletions www/django_demo_app/demo_site/app1/templates/app1/index.html
@@ -0,0 +1,17 @@
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static "app1/app1.css" %}">

<h2>Employees</h2>

<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
{% for emp in employees %}
<tr>
<td> {{ emp.first_name }}</td>
<td>{{ emp.last_name }}</td>
</tr>
{% endfor %}
</table>
3 changes: 3 additions & 0 deletions www/django_demo_app/demo_site/app1/tests.py
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions www/django_demo_app/demo_site/app1/urls.py
@@ -0,0 +1,8 @@
from django.conf.urls import url

from . import views

app_name = 'app1'
urlpatterns = [
url(r'^$', views.index, name='index'),
]
16 changes: 16 additions & 0 deletions www/django_demo_app/demo_site/app1/views.py
@@ -0,0 +1,16 @@
from django.shortcuts import render

def index(request):
context = {
"employees": [
{
"first_name": "Ram",
"last_name": "Kulkarni"
},
{
"first_name": "Emp1 First Name",
"last_name": "Emp2 Last Name"
}
]
}
return render(request, 'app1/index.html', context)
Binary file added www/django_demo_app/demo_site/db.sqlite3
Binary file not shown.
Empty file.
126 changes: 126 additions & 0 deletions www/django_demo_app/demo_site/demo_site/settings.py
@@ -0,0 +1,126 @@
"""
Django settings for demo_site project.
Generated by 'django-admin startproject' using Django 1.11.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os
import sys

sys.path.append('/var/www/html/django_demo_app/demo_site')

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*gtbud=k8sey3&r20v3&+!2kss+=y2y(vnt=i7z_!i$&zk-hy-'

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

ALLOWED_HOSTS = ['localhost']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"app1"
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'demo_site.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'demo_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.abspath(os.path.join(BASE_DIR, "static")),
]
22 changes: 22 additions & 0 deletions www/django_demo_app/demo_site/demo_site/urls.py
@@ -0,0 +1,22 @@
"""demo_site URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
url(r'^$', include('app1.urls')),
url(r'^admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions www/django_demo_app/demo_site/demo_site/wsgi.py
@@ -0,0 +1,16 @@
"""
WSGI config for demo_site project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo_site.settings")

application = get_wsgi_application()
22 changes: 22 additions & 0 deletions www/django_demo_app/demo_site/manage.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo_site.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
11 changes: 11 additions & 0 deletions www/django_demo_app/demo_site/static/app1/app1.css
@@ -0,0 +1,11 @@
tr:nth-child(even) {
background-color: yellow;
}

table {
width: 100%;
}

th {
text-align: left;
}

0 comments on commit 25e62cb

Please sign in to comment.