Reputation: 27
I encountered a problem while building a Django based site; I need to run few template updates using Ajax at the start:
$(document).ready(function () {
var trees = ['1','2','3','4','5','6']
for (i = 0; i < trees.length; i++) {
$.ajax({
'url': '/structure/showtrees',
'data': {
number:trees[i]
},
'type': 'GET',
'success': function (data) {
$("#phylo"+i).html(data);
}
});
};
});
This is redirected through urls.py which look like this: from django.conf.urls import patterns, url
from structure import views
from django.conf import settings
urlpatterns = patterns('',
...,
...,
url(r'^showtrees', views.RenderTrees, name='render')
)
Within the "views.py" is the target function:
def RenderTrees(request):
print(request.session)
number = request.session.GET['number']
tree = open('static/home/images/00'+number+'_tree.xml').read()
return render(request, 'tree'+number+'.html', {'tree':tree,'num':number})
I have the "print(session)" there as a marker, but it is never diplayed. During page load i get:
GET http://localhost:8000/structure/showtrees?number=1 500 INTERNAL SERVER ERROR 464ms
And the response is
DoesNotExist at /structure/showtrees
Structure matching query does not exist.
I was searching and searching and I couldn't find any answer to this problem.
EDIT: Full traceback here:
DoesNotExist at /structure/showtrees
Structure matching query does not exist.
Request Method: GET
Request URL: http://localhost:8000/structure/showtrees?number=1
Django Version: 1.8.4
Python Executable: /usr/bin/python3
Python Version: 3.4.3
Python Path: ['/vagrant/protwis', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '
/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages'
]
Server time: Fri, 25 Sep 2015 19:05:08 +0200
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'rest_framework',
'rest_framework_swagger',
'django_nvd3',
'common',
'api',
'documentation',
'news',
'pages',
'home',
'protein',
'family',
'residue',
'alignment',
'similaritysearch',
'similaritymatrix',
'structure',
'ligand',
'interaction',
'mutation',
'phylogenetic_trees',
'sitesearch',
'build_gpcr')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/vagrant/protwis/structure/views.py" in StructureDetails
64. crystal = Structure.objects.get(pdb_code__index=pdbname)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py" in manager_method
127. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py" in get
334. self.model._meta.object_name
Exception Type: DoesNotExist at /structure/showtrees
Exception Value: Structure matching query does not exist.
Request information:
GET:
number = '1'
POST: No POST data
FILES: No FILES data
COOKIES:
djdt = 'hide'
csrftoken = 'fH9XuekPOAU6drwD8tHHGBecE7YxMqms'
sessionid = 'lf0wjer4wyyp98ez9y5ngbcawb1xxbak'
Upvotes: 0
Views: 1140
Reputation: 27
Ok, I found the problem in my code, one of the urls in urls.py had a regexp that grabbed any string passed, and thus instead of invoking this:
url(r'^showtrees', views.RenderTrees, name='render')
it invoked the other function. Thanks for help!
Upvotes: 0
Reputation: 637
The url you are calling is
/structure/showtrees
, but in the urls.py file that you provided, you have only defined /showtrees
. That is causing your error. To fix that, change your JS call to /showtrees
or insert your urls.py file inside a new app called structure
It seems that you are using a Structure.objects.get , somewhere and Django raises a DoesNotExists exception. Check that your structure object exists on your DB.
Your problem is on this line :
crystal = Structure.objects.get(pdb_code__index=pdbname)
Check your filters on that queryset.
Upvotes: 1