Opened 16 years ago

Closed 16 years ago

#10580 closed (invalid)

django calls several views at once.

Reported by: iigor Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Is it normal behaviour?
In example below, I try to call myapp2.view.cat2_view through "/a/"
url-path. It's calling, however another views myapp1.view.cat1_viewis
also calling with it at same time.

F:\igor\apps\devel\django\temp>django-admin.py startproject myproj

F:\igor\apps\devel\django\temp>cd myproj

F:\igor\apps\devel\django\temp\myproj>python manage.py startapp myapp1

F:\igor\apps\devel\django\temp\myproj>python manage.py startapp myapp2

F:\igor\apps\devel\django\temp\myproj>python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table myapp1_cats

You just installed Django's auth system, which means you don't have
any superusers defined.
Would you like to create one now? (yes/no): yes
Username: igor
E-mail address: igor
Error: That e-mail address is invalid.
E-mail address: igor@prettysin.info
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model

#creating models & views, editing urls, settings.py. (see below)

F:\igor\apps\devel\django\temp\myproj>python manage.py runserver
Validating models...
0 errors found

Django version 1.0.2 final, using settings 'myproj.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

[22/Mar/2009 09:02:14] "GET /a/ HTTP/1.1" 200 0
[<Cats: 123>]
[22/Mar/2009 09:02:15] "GET /a/ HTTP/1.1" 200 4
[<Cats: 123>, <Cats: 123>]
[22/Mar/2009 09:02:16] "GET /a/ HTTP/1.1" 200 8
[<Cats: 123>, <Cats: 123>, <Cats: 123>]
[22/Mar/2009 09:02:17] "GET /a/ HTTP/1.1" 200 12
[<Cats: 123>, <Cats: 123>, <Cats: 123>, <Cats: 123>]
[22/Mar/2009 09:02:18] "GET /a/ HTTP/1.1" 200 16
[<Cats: 123>, <Cats: 123>, <Cats: 123>, <Cats: 123>, <Cats: 123>]
[22/Mar/2009 09:02:18] "GET /a/ HTTP/1.1" 200 20
[<Cats: 123>, <Cats: 123>, <Cats: 123>, <Cats: 123>, <Cats: 123>,
<Cats: 123>]
###########   myapp1.models
from django.db import models

# Create your models here.

class Cats(models.Model):
   name = models.CharField(max_length=255,blank=True)

   def __unicode__(self):
       return u'%s' % self.name


###########    myapp1.views
# Create your views here.
from myapp1.models  import Cats



def cat_view(request):
   cat = Cats(name="123")
   cat.save()

   # This prints to console!
   print Cats.objects.all()

   assert False
   return HttpResponse("%s" % cat.name)

#########  myapp2.views
# Create your views here.

from myapp1.models import Cats
from django.http import HttpResponse

def cat2_view(request):
   cats = Cats.objects.all()


   res = ''
   for cat in cats:
       res = res + '%s ' % cat.name

  return HttpResponse(res)


########   urls
from django.conf.urls.defaults import *

urlpatterns = patterns('',
   (r'^a/', 'myapp2.views.cat2_view'),
   (r'^', 'myapp1.views.cat_view'),
)

I replaced " (r'a/', 'myapp2.views.cat2_view'), " on "(r'',
'myapp2.views.cat2_view')," and this feature has gone away.
I guess, this's not normal behaviour.

Change History (3)

comment:1 by Alex Gaynor, 16 years ago

Resolution: invalid
Status: newclosed

The ticket tracker is for bug reports, not support questions, please use eitehr #django on freenode or the django-users mailing list.

comment:2 by iigor, 16 years ago

Resolution: invalid
Status: closedreopened

I think, this was a bugreport, not a support question. (sorry for manymany words in it)

If framework call some method and suppress all exceptions from it, it's a very strange behaviour.

I understand, that thereis version1.1, but 1.0.2 is marked as final and some of code of it may be using in future.

"I replaced " (r'a/', 'myapp2.views.cat2_view'), " on "(r, 'myapp2.views.cat2_view')," and this feature has gone away. I guess, this's not normal behaviour."

comment:3 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: reopenedclosed

Django does not call several views at once. It calls one view and returns the response from that. It's unclear from the description you've given what you're actually seeing here. We really don't need the transript of what "syncdb" outputs, but we do need a description of the error (the output from runserver isn't clear, since one would need to know what request you sent to the browser to produce which lines and whether it's all the lines that you consider th eproblem or only some of them) and what was possibly expected.

If you are having trouble understanding what's going on here, please post to django-users about the problem and people will try to help you.

"It doesn't do what I expect" is not necessarily a bug as everybody has different expectations, many of which are mutually contradictory.

Note: See TracTickets for help on using tickets.
Back to Top