Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django URL in template NoReverseMatch
I keep getting a NoReverseMatch in my base template, though I've specified a namespace and have put the proper name. Error: Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['forum/|^forums/$'] Main urls.py: from django.conf.urls import url, include from django.contrib import admin from forum.views import main_home urlpatterns = [ url(r'^$', main_home, name='home'), url(r'^admin/', admin.site.urls), url(r'^accounts/|^account/', include('accounts.urls', namespace='accounts')), url(r'^forum/|^forums/', include('forum.urls', namespace='forum')), ] Forum urls.py: from django.conf.urls import url from forum import views urlpatterns = [ url(r'^$', views.home, name='home'), ] From my template: <a class="nav-link" href="{% url 'forum:home' %}">Forum</a> -
Using schemas in Django
I am using Django 1.8.. I have been trying to make migrations of a specific app of which models have prefixes describing the schema they belong to. So here is an example: class NetworkFeature(models.Model): id_network_feature = models.AutoField(primary_key=True) class Meta: db_table = u'"schema1"."network_feature"' class ComplexElement(NetworkFeature): complex_element_class = models.ForeignKey(ComplexElementClass, blank=True, null=True) class Meta: db_table = u'"schema1"."complex_element"' I have played around with the 'schema"."table' 'schema\".\"table' and all the possible combinations and nothing seems really to solve the problem, when I do makemigrations <my-app> it works fine but when I run migrate <my-app>, it's been showing up.. django.db.utils.ProgrammingError: zero-length delimited identifier at or near """" LINE 1: CREATE INDEX ""schema1"."network_feature"_2b331646" ON "schema1"."ne... or django.db.utils.ProgrammingError: syntax error at or near "." LINE 1: CREATE INDEX "schema1"."complex_element_58db0be5" ON ... If I try to change my settings.py's search-path, it doesn't find the foreign keys.. It appears to me that there isn't a way to perform that out of the box.. -
How to add descriptions of parameters in Django Documentation?
I would like to add descriptions of parameters in Django. I am trying in the way shown below, however it doesn't work. Any suggestions? @permission_classes([UserPermission]) class ObjectByID(GenericAPIView): """ get: Return object by ID. put: Update object by ID. delete: Delete object by ID. Parameters: object_id - parameter description. """ serializer_class = ObjectSerializer def get(self, request, object_id): try: object = Object.objects.get(id= object_id) except Object.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) serializer = ObjectSerializer(object) return Response(serializer.data) ... -
Can I use fixtures to create a test from production database?
I have found a strange bug in my Django application. I have a view accessible on /people/<pk>. In tests it works just fine, but in production I have stumbled over a bug at several (just a few!) pk's: Reverse for 'single-person' with arguments '('',)' not found. 1 pattern(s) tried: ['people/(\\d+)/?$']. Since I couldn't catch it with my tests, I'd like to create another test, with the current state of the database, to debug. Also, to prevent future situations like this, I'd always like to be able to run my tests with a copy of the production database, to minimize the chances something goes wrong with the actual data. I thought it would be as straightforward as manage.py dumdata --output db-test.json and then from django.contrib.staticfiles.testing import StaticLiveServerTestCase from django.test import Client from people.models import Person class TestPeopleWithMyData(StaticLiveServerTestCase): fixtures = ['db-test.json'] def setUp(self): self.client = Client() self.client.force_login(user='test_user') def test_person(self): for person in Person.objects.all(): print('Testing %s: ' % person, end='') r = self.client.get('/people/%d' % person.pk) print(r) ... However this attempt fails: ====================================================================== ERROR: setUpClass (people.tests.test_my_data.TestPeopleWithMyData) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/username/Documents/python_projects/project/venv/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 178, in __get__ rel_obj = getattr(instance, self.cache_name) AttributeError: 'Person' object has no attribute '_added_by_cache' (I have a field named … -
Two forms in one view Django
I'm a beginner in django and I want to put two diferent registers in the same view. But also I want to make my own forms and put diferent url at the action tag. I did it in one form, but when I puy the second form, this doesn't work. This is my models.py: from django.db import models class userProfile(models.Model): usermail = models.CharField(max_length=264) username = models.CharField(max_length=264) userpass = models.CharField(max_length=264) class companyProfile(models.Model): companymail = models.CharField(max_length=264) companyname = models.CharField(max_length=264) companypass = models.CharField(max_length=264) This is my forms.py from django import forms from Pruebas_app.models import companyProfile, userProfile class registerCompany(forms.Form): companypassconf = forms.CharField() class Meta(): model = companyProfile fields = ['companymail','companyname', 'companypass'] labels = {'companymail': '', 'companyname': '', } widgets = { 'companypass': forms.PasswordInput(),} class registerUser(forms.Form): userpassconf = forms.CharField() class Meta(): model = companyProfile fields = ['usermail','username', 'userpass'] labels = {'usermail': '', 'username': '', } widgets = {'userpass': forms.PasswordInput(),} And this is my html forms. <form action="{ url 'user_register'}" method="post"> <input type="text" name="username"> <input type="email" name="usermail"> <input type="password" name="userpass"> <input type="password" name="userpassconf"> <input type="submit" value="Register"> </form> <form action="{ url 'company_register'}" method="post"> <input type="text" name="companyname"> <input type="email" name="companymail"> <input type="password" name="companypass"> <input type="password" name="companypassconf"> <input type="submit" value="Register"> </form> And this is my Views.py from django.shortcuts import … -
Link specific to user django
I have a website where a list of users looking for a service is displayed to any one who signed up to provide the service. I have the following code: {% for customer in customers %} <tr> <td style = "text-align:center">{{ customer.user.first_name|title }} {{ customer.user.last_name|title }}</td> <td style = "text-align:center">{{ customer.user.profile.address|title }}</td> <td style = "text-align:center"><a href="{% url 'claim' %}">Claim</a></td> </tr> {% endfor %} For the claim link, how can I pass information about the specific user to the linked page(say claim.html)? -
Passing Date to Url Tag Django
I am trying to pass a date to a URL Tag. Here is my url regex: url(r'^fund_details/?startDate=(?P<date_index>\d{2}-\d{2}-\d{4})/?offset(?P<date_offset>\d{2}-\d{2}-\d{4})/ and my url tag: {% url 'fund_monitor:fund_details' start_date offset %} But i get this error ValueError: invalid literal for int() with base 10: '08-18-2017' Note my start date is '08-18-2017'. I think it is because my regex is looking for a number rather than a string. However, I need the - in between the numbers. How can I achieve this? -
How to post several inputs with same name inside the one form with one submit button
Helo everypne. In a template i have one form with several inputs same name as in the example below. (the name of the inputs is allways the same, but the value is different, for example rate in one case is 743.80 and in the other form 669.32). I need to know how to post all the same name inputs without they repalce each other, but i need to treat each block of code from hotel input to select input as a different form. In php i was using name="rate[]" and then for each, but i don´t have idea, how to make with it python / django. Any idea? <form method="POST"> <input type="hidden" name="hotel" value="{{ hotel.id }}" > <input type="hidden" name="room" value="{{ room.id }}" > <input type="hidden" name="policy" value="1" > <input type="hidden" name="rate" value="743.80" > <select name="qty"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <input type="hidden" name="hotel" value="{{ hotel.id }}" > <input type="hidden" name="room" value="{{ room.id }}" > <input type="hidden" name="policy" value="1" > <input type="hidden" name="rate" value="669.32" > <select name="qty"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <input type="submit" value="Enviar"> </form> -
Customize django-allauth template
I've checked some SO questions regarding customizing signup template with not much luck. The best I found, was suggesting just to modify form action in my own template to one used by original template resulting in something like this: <form class="form-horizontal" action="/accounts/signup/?next{{request.path}}" method="POST"> There are also some answers that suggest either downloading whole project, or only templates folder and modifying directly there. It is time consuming but generally I don't feel this is the best solution out there. With my current approach as posted above I have some issues unfortunately still for which I cannot find solution. When I go to my custom signup website (mybesite/register) it works great. But when I dig dipper there are two main drawbacks: in the source code the action is telling that it will use some other place - /accounts/signup/ - I'd like to get ride of that in case of error in form it redirects to django-allauth template Is there anyway to fix those? -
Getting NoneType error on form submit with ajax
I have a problem when I submit a form through pressing ENTER. This is how my js code looks like: $.fn.api.settings.api = { 'password_reset': '/account/password_reset/' } $('.ui.form') .form({ fields: { email: 'empty' } }) .api({ action: 'password_reset', method: 'post', serializeForm: true, onSuccess: function () { $('.page.dimmer').dimmer('show'); console.log('success') } }) ; If i press the submit button, everything works alright, but if I submit the form pressing ENTER, in console I get: [18/Aug/2017 21:05:20] "POST /account/password_reset/ HTTP/1.1" 200 6 Traceback (most recent call last): File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 138, in run self.finish_response() File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 332, in send_headers self.send_preamble() File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 255, in send_preamble ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1') File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 453, in _write result = self.stdout.write(data) File "c:\users\mihai\miniconda3\Lib\socket.py", line 593, in write return self._sock.send(b) ConnectionAbortedError: [WinError 10053] An established connection has been dropped by the software on the host computer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 141, in run self.handle_error() File "C:\Users\Mihai\Desktop\dev_place\env\lib\site-packages\django\core\servers\basehttp.py", lin e 88, in handle_error super(ServerHandler, self).handle_error() File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 368, in handle_error self.finish_response() File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "c:\users\mihai\miniconda3\Lib\wsgiref\handlers.py", … -
Bootstrap - Table Within Modal Within Table
I'm using Django with Bootstrap and have a problem with a modal window. I have a table and within that I have one column where the cell is a link to the modal window. The modal window should then display another table relevant to the cell you selected. The problem is I'm trying to keep the modal div inside of a for loop because that's how I am determining which row of the table has been clicked. I've read a little on modals and seen other people have a problem when their modal div was inside table tags, so I think that's where my issue might be coming from. At the moment, the main table displays properly and the modal window opens when i click on the cell as intended. It takes the information from the for loop properly. However, when I put a table within the modal div it doesn't display in the modal window, it displays underneath the main table whether the modal has been activated or not. The modal window then only displays the header and footer with an empty body. If I get rid of the table inside the modal and use something like p's instead … -
how to call a method that is out of the class and pass the class instance to it in python django
I have a model named Klass with below code: class Klass(models.Model): title = models.CharField(max_length=50, verbose_name='class name') slug = models.SlugField(default=slug_generator, allow_unicode=True, unique=True) and it's the slug_generator function that is out of the class. def slug_generator(instance, new_slug): if new_slug is not None: slug = new_slug else: slug = slugify(instance.title) Klass = instance.__class__ qs_exists = Klass.objects.filter(slug=slug).exists() if qs_exists: new_slug = "{slug}-{randstr}".format( slug=slug, randstr=random.randint(100000,999999) ) return unique_slug_generator(instance, new_slug=new_slug) return slug in order to creating unique slugs, I want to use this function. i want to use this function for some other models. how can i pass the class to it? -
TypeError: %o format: a number is required, not unicode
def _force_i18n(self, i): test = '{% load i18n %}{% language {} %}'.format(self.language) userlanguage = test + i + '{% endlanguage %}' return userlanguage Here, self.language return either u'en' or u'fr'. I've got the following error Traceback (most recent call last): File "/home/jeremie/Projects/Work_Projects/24-django/loanwolf/messaging/utils.py", line 170, in render return Template(self._force_i18n(content)).render(Context(context)) File "/home/jeremie/Projects/Work_Projects/24-django/loanwolf/messaging/utils.py", line 126, in _force_i18n test = '{% load i18n %}{% language {} %}'.format(self.language) TypeError: %o format: a number is required, not unicode What is the better way to fix it? -
How to access to the model through a ModelMultipleChoiceField
I have a ManytoMany field in my model called 'games' : class Team(models.Model): name = models.CharField(max_length=15, null=False) tag = models.CharField(max_length=4, null=False) description = HTMLField(blank=True, null=True) logo = models.FileField(upload_to=user_directory_path, validators=[validate_file_extension], blank=True, null=True) games = models.ManyToManyField(Games, verbose_name="Jeu", null=False) owner = models.ForeignKey(User, verbose_name="Créateur") date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Date de création") update = models.DateTimeField(auto_now=True, verbose_name="Dernière modification") def __str__(self): return self.name I feed my model thanks to a form : class TeamForm(forms.ModelForm): game = Games.objects.all() games = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, required=True, queryset=game) logo = forms.ImageField(required=False, widget=forms.FileInput) class Meta: model = Team fields = ('name', 'tag', 'description', 'logo', 'games' ) In my other Model 'Games', I have a field 'logo'. I can show you : class Games(models.Model): guid = models.CharField(max_length=100, unique=True, null=False, verbose_name="GUID") title = models.CharField(max_length=100, null=False, verbose_name="Titre") logo = models.FileField(upload_to='media/games/', validators=[validate_file_extension], blank=True, null=True, verbose_name="Logo du jeu") date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Date de création") update = models.DateTimeField(auto_now=True, verbose_name="Dernière modification") def __str__(self): return self.title So, in my template I can render the ManytoMany field by calling {{form.games}}. It works fine, I have a lots of checkbox just next to the name of any games. Now, to make more cool, I also want to display the logo of the game. The problem is that the ModelMultipleChoiceField only return the game.id … -
Can I use MD5 or SHA1 hashes for filenames?
Let's consider a site where users can upload files. Can I use MD5 or SHA1 hashes of their contents as filenames? If not, what should I use? To avoid collisions. -
django one submit form several input same name
In a template i have one form with several inputs same name as in the example below. (the name of the inputs is allways the same, but the value is different, for example rate in one case is 743.80 and in the other form 669.32). I need to know how to post all the same name inputs without they repalce each other. In php i was using name="rate[]" and then for each, but i don´t have idea, how to make with it python / django. Any idea? <form method="POST"> <input type="hidden" name="hotel" value="{{ hotel.id }}" > <input type="hidden" name="room" value="{{ room.id }}" > <input type="hidden" name="policy" value="1" > <input type="hidden" name="rate" value="743.80" > <select name="qty"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <input type="hidden" name="hotel" value="{{ hotel.id }}" > <input type="hidden" name="room" value="{{ room.id }}" > <input type="hidden" name="policy" value="1" > <input type="hidden" name="rate" value="669.32" > <select name="qty"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <input type="submit" value="Enviar"> </form> -
PointField() Not Working correctly in GeoDjango
I have GDAL (using homebrew) and SQLite installed. I would like to create a teacher with a PointField() which stores long and lat values, to know their location. Later I plan on adding the ability to search by distance using something like: Teacher.objects.filter(location__distance_lte=(your_location,D(m=distance))).distance(your_location).order_by('distance') models.py from django.db import models from django.contrib.gis.db import models as gis_models from django.contrib.auth.models import User class Teacher(models.Model): user = models.ForeignKey(User, unique=True) location = gis_models.PointField() availability = models.BooleanField(default=False) However, when I run the server, I get the following error: Unhandled exception in thread started by .wrapper at 0x111c619d8> Traceback (most recent call last): File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run autoreload.raise_last_exception() File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception six.reraise(*_exception) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/init.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models() File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 978, in _gcd_import File "", line 961, in _find_and_load File "", line 950, in _find_and_load_unlocked File "", line 655, in _load_unlocked File "", line 678, in exec_module File "", line 205, … -
Django post request doing nothing
So i'm not even sure how to search for someone who had the same thing happen to them. I'm working on a django website and my form won't post to my database, instead, i get redirected to a URL containing the information that was in the forms, like this: <form id="form"> <input type="hidden" id="compinp" name="compinp"> <input maxlength="20" onkeyup="showpost()" name="title" id="titleinput"> {{ captcha }} </form> Where compinp is some other data that gets posted, {{ captcha }} is a reCaptcha checkbox that works just fine, and when everything is filled in and getting posted, instead of running the post function from views.py, instead i get redirected to this: http://localhost:8000/newentry/?compinp=XXXX&title=XXXX&g-recaptcha-response="xxxx-xxxx-xxxx" It gets posted via jQuery through a button outside of the form, though i tried to add a submit button inside it and got the exact same thing. The views.py function that handles that looks like this: def newentry(request): if request.method == "GET" and request.user.is_authenticated(): #creating objects for the view, works fine too return render(request, "newentry.html", {"champlist": complist, "captcha": captcha}) elif request.method == "POST" and request.user.is_authenticated(): captcha = Captcha(request.POST) title = request.POST.get("title", False) compname = request.POST.get("compinp", False) comp = Comp.objects.get(title=compname) if captcha.is_valid() and title and compname: newe= entry_generator(request.user, title, comp) newe.save() return … -
How to render parameter in django rest swagger?
I write Web API with django rest framework and django rest swagger. django-rest (0.0.1) django-rest-swagger (2.1.2) djangorestframework (3.6.3) I try to write Swagger YAML at the view method or APIView method. The method function is okay, and function description rendered okay. But the GET/POST method parameter can not be rendered. The view method is not using any database model, but customized model. How to render customized model field in the parameter section. How to render POST body in Swagger UI parameters section. The parameter section can not be rendered, how to display it. P.S. If I write a page with coreapi.Document the parameter could be rendered well. But this way is too complex to API docs. Wishing the YAML would be okay on APIView method or ViewSet methods. -
Sending structured form data in an HTTP POST
I'm adapting a GraphQL query to a RESTful API. The code handling this is part of a Django app. The idea is to pass the request along to a back-end microserver instead of handling the request in Django. Simplifying a bit, the query's arguments (in GraphQL's query language) are something like: pattern String address AddressInput dist Float distUnit String where AddressInput is: lines String[] city String district String division String country String postalCode String So the server ends up seeing its arguments as a Python dict, e.g. { 'dist': 1, 'distUnit': 'mi', 'address': { 'lines': ['123 Main St.'], 'city': 'Genericville', 'division': 'IA', 'country': 'US' } } How do I put that into an HTTP form in an HTTP request? I could do something like: form = QueryDict(mutable=True) form['dist'] = [1] form['distUnit'] = ['mi'] form['address.lines'] = ['123 Main St.'] form['address.city'] = ['Genericville'] form['address.division'] = ['IA'] form['address.country'] = ['US'] and process it accordingly on the server, but is there a way that's less of a kludge to handle this? -
How to use a file chooser in Django?
What I need is a button that I open the file explorer, select the file and then show the path of the file. What I've seen so far requires uploading the file and I just need the get the path. Is there another way that doesn't require uploading the file or it only can be managed like that? Thanks -
Attempted relative import beyond toplevel package in django
the code is not been working due to the error in assigning the path properly please help me with that. -
getting extra 0 using getstatusoutput command python
live_calls = commands.getstatusoutput('/usr/local/freeswitch/bin/fs_cli -x "show calls") current_live_agent = commands.getstatus('/usr/local/freeswitch/bin/fs_cli -x "show bridged_calls" |tail -2 | grep -o "[0-9]*"') print(current_live_agent) I am using above commands then getting out like 0 '0' i want to get first 0 only. Can someone help me. Thanks in advance -
Updating Deprecated South Migrations in Django to Django Migrations
I have a need to use a somewhat outdated app I found for Django. In the process of bringing it up to date, I found the need to update its 0001_initial.py file. The migrations in that file are written using the deprecated South module. My question is whether there is a straightforward way one can convert the migration of the South format to that of Django or does the entire thing need to be re-written from scratch? Here is a sample of code: # encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): def forwards(self, orm): # Adding model 'AccountType' db.create_table('accounts_accounttype', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('path', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)), ('depth', self.gf('django.db.models.fields.PositiveIntegerField')()), ('numchild', self.gf('django.db.models.fields.PositiveIntegerField')(default=0)), ('code', self.gf('django.db.models.fields.CharField')(max_length=128, unique=True, null=True, blank=True)), ('name', self.gf('django.db.models.fields.CharField')(max_length=128)), )) db.send_create_signal('accounts', ['AccountType']) # Adding model 'Account' db.create_table('accounts_account', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('name', self.gf('django.db.models.fields.CharField')(max_length=128, unique=True, null=True, blank=True)), ('description', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), ('account_type', self.gf('django.db.models.fields.related.ForeignKey')(related_name='accounts', null=True, to=orm['accounts.AccountType'])), ('code', self.gf('django.db.models.fields.CharField')(max_length=128, unique=True, null=True, blank=True)), ('primary_user', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='accounts', null=True, to=orm['auth.User'])), ('status', self.gf('django.db.models.fields.CharField')(default='Open', max_length=32)), ('credit_limit', self.gf('django.db.models.fields.DecimalField')(default='0.00', null=True, max_digits=12, decimal_places=2, blank=True)), ('balance', self.gf('django.db.models.fields.DecimalField')(default='0.00', null=True, max_digits=12, decimal_places=2)), ('start_date', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)), ('end_date', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)), ('product_range', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['offer.Range'], null=True, blank=True)), ('can_be_used_for_non_products', self.gf('django.db.models.fields.BooleanField')(default=True)), ('date_created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), )) db.send_create_signal('accounts', ['Account']) # Adding M2M table for field secondary_users on … -
I have a TemplateDoesNotExist error. I can update my models but not delete them?
I'm making my first Django site that has one app so far named clients and i keep my templates in project_name/clients/templates/clients. Like the title says i'm able to update an instance of my model Client using UpdateView in my views file and I thought I would be able to delete an instance in the same way using DeleteView but I get the error stated previously. Any help would be appreciated. I've seen other similar posts but nothing that helped me solve this problem Here's my url file: from django.conf.urls import url from . import views app_name = 'clients' url(r'^$', views.IndexView.as_view(), name='index'), # /clients/11/... could be any number url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'), # /clients/viewed/ url(r'^viewed/', views.viewed, name='viewed'), # /clients/add/ url(r'^add/$', views.ClientCreate.as_view(), name='client-add'), # /clients/3/update/ url(r'^(?P<pk>[0-9]+)/update$', views.ClientUpdate.as_view(), name='client-update'), # /clients/8/delete/ url(r'^(?P<pk>[0-9]+)/delete/$', views.ClientDelete.as_view(), name='client-delete'), ] Here's the relevant classes in my views.py: from __future__ import unicode_literals from django.views import generic from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.core.urlresolvers import reverse_lazy from django.shortcuts import render from .models import Client class ClientUpdate(UpdateView): model = Client fields = ['name', 'age', 'height', 'weight', 'history_of_head_trauma', 'profession', 'is_athlete', 'email'] success_url = reverse_lazy('clients:index') class ClientDelete(DeleteView): model = Client success_url = reverse_lazy('clients:index') Here's the div in my index.html that holds both buttons …