Re: Retrieve datas from database
Hey.. I am working for project, in that the back-end code is return in perl and am working for front-end part i.e UI using Django, Can any one can tell me how to access back-end database which is return in perl or any othere languages .?? Pls help Thank You On Mon, Jun 4, 2012 at 7:21 PM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote: > On Jun 4, 2:23 pm, by-neronwrote: > > > however, > > > > in mysite/template/index.html > > > > {% for post in latestPosts %} > > {{ post.id }} > > {% endfor %} > > prints nothing because it could not send data here. How can i send it ? > > You pass them as a Context object to the render() method of the > template - which is what your code is doing. IOW : the problem is > probably elsewhere. > > I assume that > 1/ you are running the builtin dev server with the DEBUG flag set to > True in your settings, > 2/ you do have some posts in your database, > 3/ you already made sure your code was using the right template (like > by editing something in your template and reloading the url to check > if you see the edit). > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Retrieve datas from database
On Jun 4, 2:23 pm, by-neronwrote: > however, > > in mysite/template/index.html > > {% for post in latestPosts %} > {{ post.id }} > {% endfor %} > prints nothing because it could not send data here. How can i send it ? You pass them as a Context object to the render() method of the template - which is what your code is doing. IOW : the problem is probably elsewhere. I assume that 1/ you are running the builtin dev server with the DEBUG flag set to True in your settings, 2/ you do have some posts in your database, 3/ you already made sure your code was using the right template (like by editing something in your template and reloading the url to check if you see the edit). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Retrieve datas from database
On Mon, 2012-06-04 at 05:23 -0700, by-neron wrote: > i have a project called mysite and project has an application called > blog. Project file has template/ directory which includes html files > of site.Additionally, blog application has a model like that > > class Post(models.Model): > title = models.CharField(max_length=100) > body = models.TextField() > created = models.DateTimeField() > tags = TaggableManager() > > > def __unicode__(self): > return self.title > in this app i have also view.py > > from django.template import Context, loader > from blog.models import Post > from django.http import HttpResponse > > def index(request): > latestPosts = Post.objects.all().order_by('-created')[:5] > t = loader.get_template('/mysite/templates/index.html') > c = Context({ > 'latestPosts': latestPosts, > }) > return HttpResponse(t.render(c)) > however, > > in mysite/template/index.html > > {% for post in latestPosts %} > {{ post.id }} > {% endfor %} > prints nothing because it could not send data here. How can i send > it ? > > looks ok - what about your urlconf? -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Retrieve datas from database
hi there, i'm new with Django. What i want is that retrieve some datas from db. First of all, i have a project called mysite and project has an application called blog. Project file has template/ directory which includes html files of site.Additionally, blog application has a model like that class Post(models.Model): title = models.CharField(max_length=100) body = models.TextField() created = models.DateTimeField() tags = TaggableManager() def __unicode__(self): return self.title in this app i have also view.py from django.template import Context, loader from blog.models import Post from django.http import HttpResponse def index(request): latestPosts = Post.objects.all().order_by('-created')[:5] t = loader.get_template('/mysite/templates/index.html') c = Context({ 'latestPosts': latestPosts, }) return HttpResponse(t.render(c)) however, in mysite/template/index.html {% for post in latestPosts %} {{ post.id }} {% endfor %} prints nothing because it could not send data here. How can i send it ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.