Skip to content

Commit

Permalink
reworked the settings file to use a mordern, flexible django settings…
Browse files Browse the repository at this point in the history
… layout. Updated the templates to use the static template tag. Update main.js to pull images from the static URL
  • Loading branch information
nickaigi committed Jul 29, 2015
1 parent d72ba7e commit b98e566
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ pip install -r requirements.txt

To start the server on port, for example, 8282, run the following command:
```
python manage.py runserver 0.0.0.0:8282 --insecure
python manage.py runserver 0.0.0.0:8282
```
Note: `--insecure` is needed to load the static files locally.

## Run tests

Expand Down
25 changes: 13 additions & 12 deletions django-project/public/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
Expand All @@ -12,18 +13,18 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<!-- favicon.ico and apple-touch-icon.png -->
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png" />
<link rel="shortcut icon" href="{% static 'favicon.ico' %}" type="image/x-icon">
<link rel="apple-touch-icon" href="{% static '/apple-touch-icon.png' %}" />
<link rel="apple-touch-icon" sizes="57x57" href="{% static '/apple-touch-icon-57x57.png' %}" />
<link rel="apple-touch-icon" sizes="72x72" href="{% static '/apple-touch-icon-72x72.png' %}" />
<link rel="apple-touch-icon" sizes="76x76" href="{% static '/apple-touch-icon-76x76.png' %}" />
<link rel="apple-touch-icon" sizes="114x114" href="{% static '/apple-touch-icon-114x114.png' %}" />
<link rel="apple-touch-icon" sizes="120x120" href="{% static '/apple-touch-icon-120x120.png' %}" />
<link rel="apple-touch-icon" sizes="144x144" href="{% static '/apple-touch-icon-144x144.png' %}" />
<link rel="apple-touch-icon" sizes="152x152" href="{% static '/apple-touch-icon-152x152.png' %}" />

<!-- CSS -->
<link href="css/demo.css" media="all" rel="stylesheet">
<link href="{% static 'css/demo.css' %}" media="all" rel="stylesheet">
<link href="http://emotionloop.github.io/visualCaptcha-frontend-core/dist/visualcaptcha.css" media="all" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
Expand All @@ -35,7 +36,7 @@
</head>
<body>
<div class="wrap">
<a href="/" target="_blank" class="logo"><img src="img/logo.png" alt="visualCaptcha"></a>
<a href="/" target="_blank" class="logo"><img src="{% static 'img/logo.png' %}" alt="visualCaptcha"></a>
<div class="pre-captcha-wrapper">
<div class="captcha-wrapper">
<h1>Fill in the form and submit it</h1>
Expand Down Expand Up @@ -65,7 +66,7 @@ <h1>Fill in the form and submit it</h1>
</div>

<script src="http://emotionloop.github.io/visualCaptcha-frontend-core/dist/visualcaptcha.vanilla.js"></script>
<script src="js/main.js"></script>
<script src="{% static 'js/main.js' %}"></script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down
4 changes: 2 additions & 2 deletions django-project/public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
( function( window, visualCaptcha ) {
var captcha = visualCaptcha( 'sample-captcha', {
imgPath: 'img/',
imgPath: 'static/img/',
captcha: {
numberOfImages: 5,
callbacks: {
Expand Down Expand Up @@ -63,4 +63,4 @@
// Bind that function to the appropriate link
var isFilledElement = document.getElementById( 'check-is-filled' );
_bindClick( isFilledElement, _sayIsVisualCaptchaFilled );
}( window, visualCaptcha ) );
}( window, visualCaptcha ) );
35 changes: 22 additions & 13 deletions django-project/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Django settings for django-project project.

DEBUG = False
import os

PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
Expand Down Expand Up @@ -55,11 +59,11 @@

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/'
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
'/srv/www/django.demo.visualcaptcha.net/htdocs/django-project/public',
os.path.join(PROJECT_PATH, 'public'),
)

# List of finder classes that know how to find static files in
Expand All @@ -73,12 +77,21 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'a6_js9wywxk&1**nga(nl7sc#s$&_=dpeos4ccju^sbm34e=#b'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(PROJECT_PATH, 'public')],
'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',
],
},
},
]

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
Expand All @@ -95,10 +108,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'django-project.wsgi.application'

TEMPLATE_DIRS = (
'/srv/www/django.demo.visualcaptcha.net/htdocs/django-project/public',
)

INSTALLED_APPS = (
#'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down

0 comments on commit b98e566

Please sign in to comment.