I don't see a namespace on url.py

https://docs.djangoproject.com/en/1.9/intro/tutorial03/#namespacing-url-names

On Monday, January 4, 2016 at 7:16:32 AM UTC-5, Robbie Sharma wrote:
>
> I have python and django loaded on my RaspberryPi that is wired to an LED 
> array. The web app 'iofcontrol' in my Django project is supposed to 
> activate an animation sequence of a set of LEDs.
>
>
>
>    - iofppysite is the main project file
>    - iofppysite/iofcontrol is the LED control web app!
>
>
> There is a form with 3 radio buttons (Laser 1, Laser 2, Laser 3) and 2 
> submit buttons (Acquire, Deactivate). 
>
>
> The radio buttons are linked to 1 name/variable, and the submit buttons 
> have 2 different actions. When you enter the site, you can select only one 
> "Laser" radio button and click "Acquire". It is supposed to perform an LED 
> animation based on Laser 1. You click "Deactivate" to turn the LEDs off.
>
>
> The LED code works by itself but I am having lots of issues with the POST, 
> redirect, and HttpResponse logic. I can't seem to set it up right.
>
>
> I have been getting this NoReverseMatch error or I cannot properly process 
> the POST data. I am new with Django so I have no idea what I'm doing. I 
> have been combing through tons of tutorials and problem articles but just 
> can't seem to get it right.
>
>
> Can someone help me figure this out and make it work for me?? You will 
> totally make my day!
>
>
> The error I am getting now is:
>
>
>
>
> NoReverseMatch at /  Reverse for 'submit' with arguments '()' and keyword 
> arguments '{}' not found. 0     pattern(s) tried:[u'$submit'/]
>
> And the following is highlighted in my index file:
>
> <form class="form-mini" method="post" action="{% url 'iofcontrol:submit' %}">
>
>
> My code is below:
>
>
>
> *iofppysite/iofppysite/urls.py*
>
>
> from django.conf.urls import include, url
> from django.contrib import admin
>
> urlpatterns = [
>
>     url(r'^admin/', admin.site.urls),
>     url(r'^', include('iofcontrol.urls', namespace='iofcontrol')),
> ]
>
>
> *iofppysite/iofcontrol/urls.py*
>
>
> from django.conf.urls import url
> from . import views
>
> urlpatterns = [
>
>     url(r'^', views.index, name='index'),
>     url(r'^submit/', views.submit, name='submit'),
> ]
>
>
>
> *iofppysite/iofcontrol/index.html - Form portion only*
>
>
> <form class="form-mini" method="post" action="{% url 'iofcontrol:submit' %}">
>
>         {% csrf_token %}
>
>
>
>
>             <div class="form-row">
>                 <div class="form-radio-buttons">
>
>         <div>
>             <div>
>                 <label>
>                     <span>Laser type</span>
>                 </label> 
>
>                 <label>
>                     <span>Select one to acquire</span>
>                 </label>
>
>
>                        </div>
>             <div>
>                 <label>
>                     <span>Laser 1</span>
>                 </label>
>
>                             <label>
>                                 <input type="radio" name="laser_id" value="0" 
> {% if laserAct == 0 %}    {{"checked"}}{% endif %}>
>
>                             </label>
>
>                         </div>
>
>             <div>
>                 <label>
>                     <span>Laser 2</span>
>                 </label>
>                             <label>
>                                 <input type="radio" name="laser_id" value="1" 
> {% if laserAct == 1 %}    {{"checked"}}{% endif %}>
>
>                             </label>
>
>                         </div>
>
>             <div>
>                 <label>
>                     <span>Laser 3</span>
>                 </label>
>                             <label>
>                                 <input type="radio" name="laser_id" value="2" 
> {% if laserAct == 2 %}    {{"checked"}}{% endif %}>
>
>                             </label>
>
>                         </div>
>
>
>
>
>
>                 </div>
>             </div>
>
>             <div class="form-row form-last-row">
>                 <button name="btnSubmit" type="submit" 
> value="a">Acquire</button>
>         <button name="btnSubmit" type="submit" value="s">Shutdown</button>
>             </div>
>
>         </form>
>
>
>
> iofppysite/iofcontrol/views.py
>
>
> from django.shortcuts import render
> from django.http import HttpResponseRedirect, HttpResponse
> from django.core.urlresolvers import reverse
> from django.template import loader
>
> from iofled import control
>
> # For debugging purposes, python debugger
> import time
> import pdb
>
> def index(request):
>                context = {'led_message : "Index page access"}        
>         print "A request was made: {0}".format(request)
>
>         return render(request, 'iofcontrol/index.html', Context(context))
>
> def submit(request, laser_id):
>
>         try:
>                 oLED = IoFLED()
>                 btnSubmit = request.POST['btnSubmit']
>                 laserid = request.POST['laser_id']
>
>
>
>                 print "The values of b n l: {0} and {1}".format(btnSubmit, 
> laserid)
>
>                 #If acquire was selected
>                 if(btnSubmit == "a" and laserid != False):
>
>                         oLED.deactivateLEDs()
>                         print "LED deactivated"
>                         oLED.activateLEDWiFi()
>                         print "WiFi activated"
>                         oLED.activateLEDAnim(laserid)                         
>                     
>                         print "Animating LEDs"
>                         context = {
>                          'led_nessage': "Acquiring based on Laser %s" % 
> laserid,
>                          'laserAct': laserid,
>                         }
>                 #If shutdown was selected
>                 elif(btnSubmit == "s"):
>                         oLED.deactivateLEDs()
>                         oLED.activateLEDWiFi()
>
>                 del oLED
>
>         except Exception as e:
>                 if(oLED):
>                         del oLED
>                 context = {
>                          'error_message': "A proper selction was not made. 
> %s" % e,
>
>                 }
>
>                 return render(request,'iofcontrol/index.html', context)
>         else:
>                 return HttpResponseRedirect(reverse('iofcontrol:index', args 
> = (context,)))
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f93eaa09-f4b1-4cfc-af6a-0c2541524a47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to