Trying to update a record using UpdateView Error: Circuitinfotable matching query does not exist

198 views
Skip to first unread message

Patrick Carra

unread,
Nov 25, 2019, 4:30:58 PM11/25/19
to Django users
I have a built a database application that users can search and view records from.  I am trying to incorporate an update feature to allow users to edit information the app is called editLit.  When I try to pass a parameter into the editLit app via urls into views.py I get the following error:

Environment:


Request Method: GET
Request URL: http://*****:8080/viewLit/edit/circuit/STTK-100G-18040-01-WRBB/

Django Version: 2.2.4
Python Version: 3.6.8
Installed Applications:
['editLit.apps.EditlitConfig',
 'viewLit.apps.ViewlitConfig',
 'searchLit.apps.SearchlitConfig',
 'homepage.apps.HomepageConfig',
 'base.apps.BaseConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed 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']



Traceback:

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/db_user/ciopsdb/viewLit/views.py" in viewLit
  14.     record = Circuitinfotable.objects.get(circuitid=circuitid)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/db/models/query.py" in get
  408.                 self.model._meta.object_name

Exception Type: DoesNotExist at /viewLit/edit/circuit/STTK-100G-18040-01-WRBB/
Exception Value: Circuitinfotable matching query does not exist.

My template from which I start in a view app contains the a href link below:


<a href="/viewLit/edit/circuit/{{record.circuitid}}/" target="blank" class="edit-item" title="Edit">Edit Circuit Info</a><br>

my editLit.urls.py file contains:
from django.urls import path, include
from django.conf.urls import  url
from . import views

urlpatterns= [
     path('circuit/<str:circuitid>/edit', views.editLit.as_view(),name='editLit'),
]


my editLit.views.py file contains:
from django.views.generic.edit import UpdateView

from . models import Circuitinfotable

# Create your views here.
class editLit(UpdateView):
    model=Circuitinfotable
    template="/editLit/editCircuit.html"
    fields = '__all__'


And finally my template for the editLit class is:
{% block content %}

<form action="" method="POST">
{% csrf_token %}
{{form.as_p}}

<input type="submit" value="Update">

</form>

{% endblock %}


Any ideas about what I'm doing wrong are welcome I am still new to Django.  Thanks in advance!

Patrick Carra

unread,
Nov 25, 2019, 4:36:40 PM11/25/19
to Django users
Sorry I forgot one! My models.py for this class is below:

class Circuitinfotable(models.Model):
   id1 = models.IntegerField(blank=True, null=True)
   pid = models.CharField(max_length=255, blank=True, null=True)
   circuitid = models.CharField(primary_key=True, max_length=255, blank=False, null=False)
   bandwidth = models.CharField(max_length=255, blank=True, null=True)
   region = models.CharField(max_length=255, blank=True, null=True)
   bw = models.IntegerField(blank=True, null=True)
   tableaupathname = models.CharField(max_length=255, blank=True, null=True)
   handoffalocaddress = models.CharField(max_length=255, blank=True, null=True)
   handoffaloccity = models.CharField(max_length=255, blank=True, null=True)
   handoffalocst = models.CharField(max_length=255, blank=True, null=True)
   alocationaddress = models.CharField(max_length=255, blank=True, null=True)
   alocationcity = models.CharField(max_length=255, blank=True, null=True)
   alocst = models.CharField(max_length=255, blank=True, null=True)
   handoffzlocaddress = models.CharField(max_length=255, blank=True, null=True)
   carrier = models.CharField(max_length=255, blank=True, null=True)
   handoffzloccity = models.CharField(max_length=255, blank=True, null=True)
   handoffzlocst = models.CharField(max_length=255, blank=True, null=True)
   zlocationaddress = models.CharField(max_length=255, blank=True, null=True)
   zlocationcity = models.CharField(max_length=255, blank=True, null=True)
   zlocst = models.CharField(max_length=255, blank=True, null=True)
   segmentid = models.CharField(max_length=255, blank=True, null=True)
   segmenttype = models.CharField(max_length=255, blank=True, null=True)
   status = models.CharField(max_length=255, blank=True, null=True)
   purpose = models.CharField(max_length=255, blank=True, null=True)
   installdate = models.DateField(blank=True, null=True)
   termdate = models.DateField(blank=True, null=True)
   termlengthmos = models.IntegerField(blank=True, null=True)
   legacy = models.CharField(max_length=255, blank=True, null=True)
   installciopsticket = models.CharField(max_length=255, blank=True, null=True)
   retermciopsticket = models.CharField(max_length=255, blank=True, null=True)
   discociopsticket = models.CharField(max_length=255, blank=True, null=True)
   notes = models.CharField(max_length=255, blank=True, null=True)
   kma = models.CharField(max_length=255, blank=True, null=True)
   group = models.IntegerField(blank=True, null=True)
   cktidkey = models.IntegerField(blank=True, null=True)
   visiolink = models.CharField(max_length=255, blank=True, null=True)
   latestjiraticket = models.CharField(max_length=255, blank=True, null=True, unique=True)
   disconnectdate = models.DateField(blank=True, null=True)
   segmentname = models.CharField(max_length=255, blank=True, null=True)
   mrcnew = models.TextField(blank=True, null=True)  # This field type is a guess.
   termyrs = models.IntegerField(blank=True, null=True)
   monthbudget = models.IntegerField(blank=True, null=True)
   monthdisco = models.IntegerField(blank=True, null=True)
   mrcold = models.TextField(blank=True, null=True)  # This field type is a guess.
   kmz = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
       managed = False
       db_table = 'circuitinfotable'

    def __str__(self):
       return self.circuitid

    def get_absolute_url(self):
       return reverse('home')



Gil Obradors

unread,
Nov 25, 2019, 5:20:07 PM11/25/19
to django...@googlegroups.com
Hi!
Matching query doesn't exists says that this entry with this id not exists in db....
Are you sure that this object exists? STTK-100G-18040-01-WRBB

Can you open a shell and:

from xxx.models import Circuitinfotable
obj = Circuitinfotable.objects.all()
print(len(obj))
obj = Obj.get(circuitid='STTK-100G-18040-01-WRBB')
print(obj)


Are you following me?
Or confirm that exists via admin?




Missatge de Patrick Carra <pcar...@gmail.com> del dia dl., 25 de nov. 2019 a les 22:37:
--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b407aac9-aec7-4e45-b91a-9864c4be2d80%40googlegroups.com.

Patrick Carra

unread,
Nov 26, 2019, 8:24:34 AM11/26/19
to Django users
Thanks for the reply Gil i did this and was able to find this object.

Python 3.6.8 (default, Aug  7 2019, 17:28:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from editLit.models import Circuitinfotable
>>> obj = Circuitinfotable.objects.all()
>>> print(len(obj))
573
>>> obj = Obj.get(circuitid='STTK-100G-18040-01-WRBB')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'Obj' is not defined
>>> obj = obj.get(circuitid='STTK-100G-18040-01-WRBB')
>>> print(obj)
STTK-100G-18040-01-WRBB

Patrick Carra

unread,
Nov 26, 2019, 10:46:42 AM11/26/19
to Django users
Could it possibly be that it is trying to match this entire value? /viewLit/edit/circuit/STTK-100G-18040-01-WRBB/ and if so what am I doing wrong in my urls and views that I am not dropping /viewLit/edit/circuit/?

Gil Obradors

unread,
Nov 26, 2019, 11:02:39 AM11/26/19
to django...@googlegroups.com
May be,

Or you aren t querying for circuitid ( by view class code) , normally the urls are with the int pk parameter...
For this, django-debug-toolbar can help to see what are you quering to db, i recommend to install and play with this great tool

I will read about, i want to know whats happening




El dt., 26 de nov. 2019, 16:47, Patrick Carra <pcar...@gmail.com> va escriure:
Could it possibly be that it is trying to match this entire value? /viewLit/edit/circuit/STTK-100G-18040-01-WRBB/ and if so what am I doing wrong in my urls and views that I am not dropping /viewLit/edit/circuit/?

--
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 django-users...@googlegroups.com.

Gil Obradors

unread,
Nov 26, 2019, 11:53:22 AM11/26/19
to django...@googlegroups.com
Can you try to add to the view class this argument?


pk_url_kwarg = 'circuitid'

And check what query is doing with django-debug-toolbar

Missatge de Gil Obradors <gil.ob...@gmail.com> del dia dt., 26 de nov. 2019 a les 17:01:

Patrick Carra

unread,
Nov 26, 2019, 12:04:04 PM11/26/19
to Django users
I installed the django-debug-toolbar but its not doing anything. I imported it added it to settings.py installed apps and middleware, added the if statement to the project level urls.py and Debug is set to True.

Gil Obradors

unread,
Nov 26, 2019, 1:04:01 PM11/26/19
to django...@googlegroups.com

and

Configuring Internal IPs

The Debug Toolbar is shown only if your IP address is listed in the INTERNAL_IPS setting. This means that for local development, you must add '127.0.0.1' to INTERNAL_IPS; you’ll need to create this setting if it doesn’t already exist in your settings module:

INTERNAL_IPS = [
    # ...
    '127.0.0.1',
    # ...
]

Missatge de Patrick Carra <pcar...@gmail.com> del dia dt., 26 de nov. 2019 a les 18:04:
I installed the django-debug-toolbar but its not doing anything. I imported it added it to settings.py installed apps and middleware, added the if statement to the project level urls.py and Debug is set to True.

--
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 django-users...@googlegroups.com.

Patrick Carra

unread,
Nov 26, 2019, 1:56:56 PM11/26/19
to Django users
Okay I have worked on it I do have the toolbar on there but it's not display correctly it shows up at the bottom of each page and looks like this:

«

Versions

loading

Time

loading

Settings from ciopsdb.settings

loading

Headers

loading

Request

loading

SQL queries from 1 connection

loading

Static files (134 found, 0 used)

loading

Templates (1 rendered)

loading

Cache calls from 1 backend

loading

Signals

loading

Log messages

loading

Gil Obradors

unread,
Nov 26, 2019, 3:24:38 PM11/26/19
to django...@googlegroups.com
After the page is loaded, click to SQL queries and paste or make a screenshot of the content.
In this tab you will see all transactions to DB


Missatge de Patrick Carra <pcar...@gmail.com> del dia dt., 26 de nov. 2019 a les 19:57:
--
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 django-users...@googlegroups.com.

Patrick Carra

unread,
Nov 26, 2019, 3:53:39 PM11/26/19
to Django users
I figured out the weirdness with the django-debug-toolbar I wasn't serving my static files from the apache/mod_wsgi configuration.  After I figured that out this is what I have now:

 QueryTimelineTime (ms)Action
 +
SELECT ••• FROM "circuitinfotable" WHERE "circuitinfotable"."circuitid" = 'edit/circuit/STTK-100G-18040-01-WRBB'
53.76007636826474%
2.42
 +
SELECT ••• FROM "circuitinfotable" LIMIT 21
15.353203224437845%
0.69
 +
SELECT ••• FROM "django_session" WHERE ("django_session"."expire_date" > '2019-11-26T20:52:52.260094+00:00'::timestamptz AND "django_session"."session_key" = '0b3x3t7gx8sbl09y5vsbonxtlfmynib4')
16.928298684768777%
0.76
 +
SELECT ••• FROM "auth_user" WHERE "auth_user"."id" = 1

Gil Obradors

unread,
Nov 26, 2019, 4:01:05 PM11/26/19
to django...@googlegroups.com
Yeah!
Can you see the error?
WHERE "circuitinfotable"."circuitid" = 'edit/circuit/STTK-100G-18040-01-WRBB'
would be : WHERE "circuitinfotable"."circuitid" = 'STTK-100G-18040-01-WRBB'

Link incorrect, or uls pattern incorrect
<a href="/viewLit/edit/circuit/{{record.circuitid}}/" target="blank" class="edit-item" title="Edit">Edit Circuit Info</a><br>



Missatge de Patrick Carra <pcar...@gmail.com> del dia dt., 26 de nov. 2019 a les 21:54:
--
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 django-users...@googlegroups.com.

Patrick Carra

unread,
Nov 26, 2019, 4:08:54 PM11/26/19
to Django users
Yea! This toolbar is an awesome tool thanks for the tip.  So now I guess I'm not understanding how to route url's really.  The a href is:
 <a href="/viewLit/edit/jira/{{record.circuitid}}" class="edit-item" target="blank" title="Edit">Edit Jira Info</a><br>

My project level urls.py is:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
import debug_toolbar

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('homepage.urls')),
    path('searchlit/', include('searchLit.urls')),
    path('viewLit/edit/', include('editLit.urls')),
    path('viewLit/', include('viewLit.urls')),
    path('edit/', include('editLit.urls')),
    path(r'^__debug__/', include(debug_toolbar.urls)),
]

my editLit urls.py is:
from django.urls import path, include
from django.conf.urls import  url
from . import views

urlpatterns= [
     path('edit/circuit/<str:circuitid>', views.editLit.as_view(),name='editLit'),
]


And finally my editLit views.py is:
class editLit(UpdateView):
    pk_url_kwarg = 'circuitid'
    model=Circuitinfotable
    template="/editLit/editCircuit.html"
    fields = '__all__'


So I don't understand either how to just pull the param without the edit/circuit/ part or can that be stripped before it is passed to the view?

Gil Obradors

unread,
Nov 26, 2019, 4:16:11 PM11/26/19
to django...@googlegroups.com
Easy, urlpatterns from  editLit.urls must be:

urlpatterns= [
     path('jira/<str:circuitid>', views.editLit.as_view(),name='editLit'),
]


Missatge de Patrick Carra <pcar...@gmail.com> del dia dt., 26 de nov. 2019 a les 22:09:
--
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 django-users...@googlegroups.com.

Patrick Carra

unread,
Nov 26, 2019, 4:34:45 PM11/26/19
to Django users
Correct me if i'm wrong but I think you meant:

urlpatterns= [
     path('circuit/<str:circuitid>', views.editLit.as_view(),name='editLit'),
]

I did make that change but the results were the same.

Patrick Carra

unread,
Nov 26, 2019, 4:39:49 PM11/26/19
to Django users
Ha that was my mistake my brain has turned to mush anyhow the change was made and it still is broken :(

Gil Obradors

unread,
Nov 26, 2019, 4:42:02 PM11/26/19
to django...@googlegroups.com
This is the link ?
 <a href="/viewLit/edit/jira/{{record.circuitid}}" class="edit-item" target="blank" title="Edit">Edit Jira Info</a><br>


My project level urls.py is:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
import debug_toolbar

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('homepage.urls')),
    path('searchlit/', include('searchLit.urls')),
    path('viewLit/edit/', include('editLit.urls')),
    path('viewLit/', include('viewLit.urls')),
    path('edit/', include('editLit.urls')),
    path(r'^__debug__/', include(debug_toolbar.urls)),
]

So, editLit.urls will be:

[...]
urlpatterns = [
        [...]
     path('jira/<str:circuitid>', views.editLit.as_view(),name='editLit'),
        [....]

]




Missatge de Patrick Carra <pcar...@gmail.com> del dia dt., 26 de nov. 2019 a les 22:35:
--
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 django-users...@googlegroups.com.

Patrick Carra

unread,
Nov 26, 2019, 4:59:57 PM11/26/19
to Django users
It's actually this I copy and pasted the wrong thing:

<a href="/viewLit/edit/circuit/{{record.circuitid}}/" target="blank" class="edit-item" title="Edit">Edit Circuit Info</a><br>



My project level urls.py is:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
import debug_toolbar

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('homepage.urls')),
    path('searchlit/', include('searchLit.urls')),
    path('viewLit/edit/', include('editLit.urls')),
    path('viewLit/', include('viewLit.urls')),
    path('edit/', include('editLit.urls')),
    path(r'^__debug__/', include(debug_toolbar.urls)),
]

So, editLit.urls will be:

[...]
urlpatterns = [
        [...]
     path('circuit/<str:circuitid>', views.editLit.as_view(),name='editLit'),
        [....]

]

But it doesn't work it gives me the same error:

Raja Sekar Sambath

unread,
Nov 27, 2019, 12:26:03 AM11/27/19
to django...@googlegroups.com
Hi,
    path('viewLit/edit/', include('editLit.urls')),
    path('viewLit/', include('viewLit.urls')),
    path('edit/', include('editLit.urls')),

look at above in project level urls.py, give a try by commenting any one 

--
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 django-users...@googlegroups.com.


--
Thanks & Regards,

Raja Sekar Sampath

Patrick Carra

unread,
Nov 27, 2019, 10:52:43 AM11/27/19
to Django users
Raja that was a great suggestion thank you!  Once a started playing around with the urls in the project level I found that it was still being routed to viewLit despite the edit/ in the url I was passing.  I decided to put all these classes into the same app viewLit/views.py and now my parameter is correct.

SELECT ••• FROM "circuitinfotable" WHERE "circuitinfotable"."circuitid" = 'STTK-100G-18040-01-WRBB'

The problem I am now having is that UpdateView cannot find the template circuitinfotable_form.html
Environment:


Request Method: GET

Django Version: 2.2.4
Python Version: 3.6.8
Installed Applications:
['editLit.apps.EditlitConfig',
 'viewLit.apps.ViewlitConfig',
 'searchLit.apps.SearchlitConfig',
 'homepage.apps.HomepageConfig',
 'base.apps.BaseConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'debug_toolbar']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template loader postmortem
Django tried loading these templates, in this order:

Using engine django:
    * django.template.loaders.filesystem.Loader: /home/db_user/ciopsdb/base/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.filesystem.Loader: /home/db_user/ciopsdb/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/editLit/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/viewLit/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/searchLit/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/homepage/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/base/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/contrib/admin/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/contrib/auth/templates/viewLit/circuitinfotable_form.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: /home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/debug_toolbar/templates/viewLit/circuitinfotable_form.html (Source does not exist)



Traceback:

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  145.                 response = self.process_exception_by_middleware(e, request)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  143.                 response = response.render()

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/template/response.py" in rendered_content
  81.         template = self.resolve_template(self.template_name)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/template/response.py" in resolve_template
  63.             return select_template(template, using=self.using)

File "/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/template/loader.py" in select_template
  47.         raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)

Exception Type: TemplateDoesNotExist at /viewLit/STTK-100G-18040-01-WRBB/edit
Exception Value: viewLit/circuitinfotable_form.html


My viewLit/models.py is:
class Circuitinfotable(models.Model):
    id1 = models.IntegerField(blank=True,null=True)
    pid = models.CharField(max_length=255, blank=True, null=True)
    circuitid = models.CharField(primary_key=True, max_length=255, blank=True, null=False)
    def get_absolute_url(self):
        return reverse()


My viewLit/views.py is now:
import re
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import TemplateView
from django.views.generic.edit import UpdateView
from django.urls import reverse

from . models import Circuitinfotable, Budgettable, Xcinventorytable

# Create your views here.
def viewLit(request, circuitid):
    ruleList=["/SB", "/ZYO", "/ZYO /", "/MS", "/CLVI", "ELG"]
    for rule in ruleList:
        if(len(re.findall(rule + "$", circuitid))>0):
            circuitid=re.sub(rule+"$","/"+rule, circuitid)
    record = Circuitinfotable.objects.get(circuitid=circuitid)
    template = 'viewLit/viewCircuit.html'
    context = {'record':record}
    return render(request, template, context)


class editLit(UpdateView):
    pk_url_kwarg = 'circuitid'
    model=Circuitinfotable
    template="/viewLit/editCircuit.html"
    fields='__all__'


my viewLit.urls.py is now:
from django.urls import path, include
from django.conf.urls import  url
from . import views

urlpatterns= [
     path('<path:circuitid>/', views.viewLit, name='viewLit'),
     path('<path:circuitid>/edit', views.editLit.as_view(), name='editLit'),
]


and my template is:
<html text/html>

<body>
{% block content %}

<form action="" method="POST">
{% csrf_token %}
{{form.as_p}}

<input type="submit" value="Update">

</form>

{% endblock %}
</body>
</html>


I understand this has kind of moved to a new topic and I can start a new post if that is more appropriate than answering here.

Raja Sekar Sambath

unread,
Nov 27, 2019, 11:22:20 AM11/27/19
to django...@googlegroups.com
Hey Patrick,

Can you post forms.py here?

--
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 django-users...@googlegroups.com.

Patrick Carra

unread,
Nov 27, 2019, 11:26:25 AM11/27/19
to Django users
I didn't have one.  I thought UpdateView would create the form for me.  But I was working the problem and made one:
from django.forms import ModelForm
from . models import Circuitinfotable

class CircuitinfotableForm(ModelForm):
    class Meta:
        model = Circuitinfotable
        fields = '__all__'


So I also changed my view:
class editLit(UpdateView):
    pk_url_kwarg = 'circuitid'
    model=Circuitinfotable
    form_class= CircuitinfotableForm
    template="/viewLit/editCircuit.html"
#    fields='__all__'




franz ulenaers

unread,
Nov 27, 2019, 11:34:24 AM11/27/19
to django...@googlegroups.com
put your template 'circuitinfotable_form.html' on one of your folders :
/home/db_user/ciopsdb/base/templates/viewLit/circuitinfotable_form.html
/home/db_user/ciopsdb/templates/viewLit/circuitinfotable_form.html
/home/db_user/ciopsdb/editLit/templates/viewLit/circuitinfotable_form.html
/home/db_user/ciopsdb/viewLit/templates/viewLit/circuitinfotable_form.html
/home/db_user/ciopsdb/searchLit/templates/viewLit/circuitinfotable_form.html
/home/db_user/ciopsdb/homepage/templates/viewLit/circuitinfotable_form.html


Patrick Carra

unread,
Nov 27, 2019, 11:41:04 AM11/27/19
to Django users
I don't have a circuitinfotable_form.html.  I never specified circuitinfotable_form in any of my code.  What should that form contain?  My /viewLit/editCircuit.html form contains the following:

<html text/html>

<body>
{% block content %}

<form action="" method="POST">
{% csrf_token %}
{{form.as_p}}

<input type="submit" value="Update">

</form>

{% endblock %}
</body>
</html>

Shouldn't that suffice for the template form?  What is calling the circuitinfotable_form.html?

Patrick Carra

unread,
Nov 27, 2019, 11:49:44 AM11/27/19
to Django users
okay so I dumped all the contents of my editCircuit.html into a file called circuitinfotable_form.html and now I get my form.  But I still don't understand why I had to use this name since I never specified it anywhere.
Reply all
Reply to author
Forward
0 new messages