Shame on me. The problem was that i mixed SimpleDocTemplate (which the examples were based on), with BaseDocTemplate, which i used. And BaseDocTemplate needs an extra PageTemplate defined. So this code basically works:
def generate_pdf(request): response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=somefilename.pdf' template = PageTemplate('normal', [Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')]) doc = BaseDocTemplate(filename=response,pagesize=A4,pageTemplates=template) styles = getSampleStyleSheet() Document = [Paragraph('rd', styles["Title"])] Document.append(Spacer(1,50)) doc.build(Document) return response Thanks all for the help! Sven On Wed, Mar 31, 2010 at 12:23 AM, Sven Richter <sver...@googlemail.com> wrote: > Hm, what makes me wonder is this one: > IndexError at /office/job//admin/job/offer/generate/pdf/ > This is a url that is not accessible, cause it does not exist, at > least i never defined it in any urls.py. > Maybe thats the problem? Django tries to access a url which doesnt exist? > > > Greetings > Sven > > On Tue, Mar 30, 2010 at 10:55 PM, Sven Richter <sver...@googlemail.com> wrote: >> On Tue, Mar 30, 2010 at 9:08 PM, Paulo Almeida >> <igcbioinformat...@gmail.com> wrote: >>> Ok, that is not easy to debug with so little information. Is the IndexError >>> in views.py? Maybe there is a mistake in urls.py, caused by adding the url >>> for the generate_pdf view? >> >> Hm, its indeed hard. I really dont know what that Error will tell me. >> My Application is a very basic one. Up to now i do everything in the >> admin interface. The only url defined is the one to view the pdf file: >> >> urls.py: >> urlpatterns = patterns('', >> # Example: >> # (r'^eiwomisa/', include('eiwomisa.foo.urls')), >> >> # Uncomment the admin/doc line below and add 'django.contrib.admindocs' >> # to INSTALLED_APPS to enable admin documentation: >> # (r'^admin/doc/', include('django.contrib.admindocs.urls')), >> >> # Uncomment the next line to enable the admin: >> (r'^admin/', include(admin.site.urls)), >> (r'^project/task/', include('project.task.urls')), >> (r'^office/job/', include('office.job.urls')), >> ) >> >> offic/job/urls.py: >> >> from django.conf.urls.defaults import * >> >> urlpatterns = patterns('office.job.views', >> (r'/offer/generate/pdf/$', 'generate_pdf', '', >> 'office_job_generate_offer_pdf'), >> ) >> >> and here is my views.py: >> >> def generate_pdf(request): >> response = HttpResponse(mimetype='application/pdf') >> response['Content-Disposition'] = 'attachment; filename=somefilename.pdf' >> >> doc = BaseDocTemplate(filename=response,pagesize=A4) >> styles = getSampleStyleSheet() >> Document = [Paragraph('rd', styles["Title"])] >> Document.append(Spacer(1,50)) >> date_now = unicode(datetime.now().strftime("%B %d, %Y")) >> Document.append(Paragraph("PDF created on " + date_now, styles["Normal"])) >> Document.append(Spacer(1,10)) >> doc.build(Document) >> >> I have tried the same "setup" with the canvas.Canvas example from the >> django documentation, and it worked. All i changed here is from canvas >> to document. >> >> Greetings >> Sven >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.