from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from django.http import HttpResponse, Http404
import s7

import light

def index(request):
    s7conn = s7.S7Comm("10.0.3.9")

    lights = light.loadAll(s7conn)
    context = { 'lights' : lights }
    return render(request, "lights.html", context)

@csrf_exempt
def lightswitch(request, action):
    s7conn = s7.S7Comm("10.0.3.9")
    l = light.Light("", request.REQUEST["id"], s7conn)

    if action != "toggle":
        raise Http404

    if not l.toggle():
        raise Http404

    return HttpResponse()

@@ -153,16 +153,37 @@
  light%0A%0A
+PLC_IP = %2210.0.3.9%22%0A%0A
 def inde
@@ -217,26 +217,22 @@
 .S7Comm(
-%2210.0.3.9%22
+PLC_IP
 )%0A%0A    l
@@ -419,26 +419,22 @@
 .S7Comm(
-%2210.0.3.9%22
+PLC_IP
 )%0A    l 

Move IP address to a constant at least