Trying to delete uploaded images (SuspiciousOperation)
Hello, I've been running into a problem while trying to delete uploaded images. The error I get is: SuspiciousOperation: Attempted access to '/media/artists/12-stones/ 154339.jpg' denied. After reading around it looks like the error is due to the fact that it's looking for the image in the wrong place (notice first slash, / media/ doesn't exist on the filesystem) My MEDIA_ROOT and MEDIA_URL are: MEDIA_ROOT = '/home/tsoporan/site/media/' MEDIA_URL = "/media/ My models upload_to parameter is passed this function: def get_artist_path(instance, filename): return os.path.join('artists', slugify(instance.name), filename) I have no idea why the path is being determined as '/media/etc/ etc/' .. My questions are: 1) How can I fix this problem for future uploads? 2) Is it possible to fix my current images' paths without having to reupload? Regards, Titus -- 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.
How would I do this ...
Hello! I have hit a small road block in designing a fairly simple CMS application: My url pattern is: url(r'^(?P[A-Za-z-_//]+)/$', page_handler, name='page_handler') I'm capturing whatever URL handing it off to a page handler view function that matches up a Page by slug and returns it .. this works great for textual content. View: def page_handler(request, url=None): #Default to page root when no url if url == None: page = get_object_or_404(Page, id=1) else: page = get_object_or_404(Page, slug__exact=url) if not page.template: template = 'cms/default.html' else: template = page.template return render_to_response(template, { 'page': page, 'request': request, }) I am trying to figure out if there is a way to pass additional context to a template from the view, say I have made a contact page but this page needs to access a form, currently I don't know how I would be able to do that, that is, to pass the form context to whatever template the Page specifies. Normally I'd just map a URL to a "contact" view function that handles the form and passes it off to a template. I am trying to be efficient about this without "hard-coding" that in ... if that makes sense. Any help is appreciated! Regards, Titus --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How would I do this ...
I have a small problem, fairly new to django: I currently am building a small CMS application, and its all handled by a Page model. The url for this is: --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Context to a Template
Hello, I am attempting to write a small CMS application in hopes of learning Django more in depth. Currently a page is just for editing textual content and it gets sent to a template (much like the flatpage) the problem is if I had a contact page, that happens to have a form on it, what would be the best approach to passing the "form" context to the template? Would I have to create a seperate template for each page that has more than just textual content? All my pages are handled by a simplistic page_handler view that takes a url and checks the Page model ... so I'm confused as to how I could dynamically pass a context to any page that I wanted. This might not be the right approach, but I don't see the way to do it. What I'd like to be able to do is just edit a page in the admin and be able to write {{ form }} or {{ contact_form }} and for it to know what context I am referring to, if that makes sense. Much appreciate, thanks! --~--~-~--~~~---~--~~ 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: Two forms one page
Oh thanks! I didn't realize you could do that, it works now. I am using request.POST.__contains__(key), I think this is what you meant. =) Titus On Feb 8, 4:25 am, Horst Gutmann <ze...@zerokspot.com> wrote: > You could also assign the submit buttons a name (each its own name), > check request.POST for that name and then validate the respective form > :-) > > -- Horst > > On Sun, Feb 8, 2009 at 10:18 AM, tsop <tso...@gmail.com> wrote: > > Hello, > > I have a small problem here, I want to display two forms on the same > > page and I need both forms to validate/submit independently from one > > another. The problem I am having is that there is no way to tell which > > form is being submitted to, if they are both left empty and one submit > > is clicked both raise validation errors. > > > Since the view and template is quite a bit of code I've pasted them to > > a pastebin: > > > The view: > >http://dpaste.com/118076/ > > > The template: > >http://dpaste.com/118077/ > > > King Regards, > > Titus --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Two forms one page
Hello, I have a small problem here, I want to display two forms on the same page and I need both forms to validate/submit independently from one another. The problem I am having is that there is no way to tell which form is being submitted to, if they are both left empty and one submit is clicked both raise validation errors. Since the view and template is quite a bit of code I've pasted them to a pastebin: The view: http://dpaste.com/118076/ The template: http://dpaste.com/118077/ King Regards, Titus --~--~-~--~~~---~--~~ 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: A Django Comic Site Issues
Hello, Thanks for your reply Daniel, that along with setting ordering on the Comic model seems to have fixed it. Titus On Dec 28, 9:55 am, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > On Dec 28, 5:35 am, tsop <tso...@gmail.com> wrote: > > > > > Hey, > > I'm quite new to django but I ran into a small problem maybe someone > > can shed some light onto: > > > models.py > > > class Comic(models.Model): > > title = models.CharField(max_length=80, help_text='Title of > > comic.') > > series = models.ForeignKey(ComicSeries, help_text='Which > > series comic belongs to.') > > image = models.ImageField(upload_to='tmp', help_text='A > > comic.') > > page_number = models.IntegerField(editable=False) > > def __unicode__(self): > > return "%s - %s" % (self.title, self.series) > > > def get_absolute_url(self): > > #return "/comics/%s/?page=%d" % (self.series.slug, > > self.page_number) > > return "/comics/%s/%d" % (self.series.slug, > > self.page_number) > > > def save(self): > > if not self.page_number: > > count = len(Comic.objects.filter > > (series=self.series)) > > self.page_number = count + 1 > > > super(Comic, self).save() > > > -- > > > admin.py > > > class ComicInline(admin.StackedInline): > > model = Comic > > extra = 20 > > > (Multi form uploading) > > > When saving a comic it should also save the right page number, the > > reason I'm using my own page_numbers is because each comic belongs to > > a series and if its the first in that series it should be page number > > one, so we're not using comic id or anything. > > > It works for the most part, the page number increments as the comics > > are saved, but when you start deleting previous comics and adding new > > ones it doesn't save in the right order anymore. > > > All I really need to know is if there's a way we can make sure that > > when multi form saves, it saves them in either the right order, or pre- > > populates the page_number field with the right values. > > Instead of getting the total number of comics in the series, what you > want to do is get the highest existing page number. This is one way to > do it: > Comic.objects.filter(series=self.series).order_by('-page_number') > [0].page_number > > This just reverse-orders the comic series by page number, and takes > the page_number from the first object - which will be the highest. > -- > DR. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
A Django Comic Site Issues
Hey, I'm quite new to django but I ran into a small problem maybe someone can shed some light onto: models.py class Comic(models.Model): title = models.CharField(max_length=80, help_text='Title of comic.') series = models.ForeignKey(ComicSeries, help_text='Which series comic belongs to.') image = models.ImageField(upload_to='tmp', help_text='A comic.') page_number = models.IntegerField(editable=False) def __unicode__(self): return "%s - %s" % (self.title, self.series) def get_absolute_url(self): #return "/comics/%s/?page=%d" % (self.series.slug, self.page_number) return "/comics/%s/%d" % (self.series.slug, self.page_number) def save(self): if not self.page_number: count = len(Comic.objects.filter (series=self.series)) self.page_number = count + 1 super(Comic, self).save() -- admin.py class ComicInline(admin.StackedInline): model = Comic extra = 20 (Multi form uploading) When saving a comic it should also save the right page number, the reason I'm using my own page_numbers is because each comic belongs to a series and if its the first in that series it should be page number one, so we're not using comic id or anything. It works for the most part, the page number increments as the comics are saved, but when you start deleting previous comics and adding new ones it doesn't save in the right order anymore. All I really need to know is if there's a way we can make sure that when multi form saves, it saves them in either the right order, or pre- populates the page_number field with the right values. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---