Re: Using success_url with reverse() in class-based generic view

2018-03-11 Thread Mayur Karmakar
Try to import reverse_lazy form "django.core.urlresolvers" in your views.py 
and declare the DeleteView as:-

class MyDeleteView(DeleteView):
  model = models.YourModelName
  success_url = 
reverse_lazy('Your_app_name_for_urls.py':urlpattern_name_your_wanna_redirect_to)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3dd772e-a4b1-4777-9b82-54113fddeeb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: using success_url

2014-01-12 Thread shmengie


On Friday, January 10, 2014 2:36:56 PM UTC-5, Brad Rice wrote:
>
> I can't seem to find success using success_url
>
> If I try this in my urls.py file
>
> url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), 
> name='answers'),
>
> and then in my view:
>

class AnswersCreate(CreateView):
success_url = '/requstform/success'
model=myModel
...
 

> def form_valid(self, form):
> obj = form.save(commit=False)
> obj.created_by = self.request.user
> obj.save()
> return HttpResponseRedirect(self.get_success_url())
>
 
A mixin may be necessary, to provide get_success_url method added to the 
class.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f5490254-6cbc-4beb-90f7-92549268d731%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: using success_url

2014-01-11 Thread trojactory
Hi Brad,

If you are using FormView, then you can set the success_url as mentioned in 
the 
docs<https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.success_url>
.

Cheers,
Arun

On Saturday, January 11, 2014 1:06:56 AM UTC+5:30, Brad Rice wrote:
>
> I can't seem to find success using success_url
>
> If I try this in my urls.py file
>
> url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), 
> name='answers'),
>
> and then in my view:
>
> def form_valid(self, form):
> obj = form.save(commit=False)
> obj.created_by = self.request.user
> obj.save()
> return HttpResponseRedirect(self.get_success_url())
>
> I get a successful save but it does not take me to the next url defined in 
> success_url
>
> Is there another way to do it, or what am I doing wrong?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/35cc977f-a0f7-453c-9523-d22f82a0acd2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


using success_url

2014-01-10 Thread Brad Rice
I can't seem to find success using success_url

If I try this in my urls.py file

url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), 
name='answers'),

and then in my view:

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
return HttpResponseRedirect(self.get_success_url())

I get a successful save but it does not take me to the next url defined in 
success_url

Is there another way to do it, or what am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/775978f7-774f-4ef5-b12e-9e97f3c3864a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using success_url with reverse() in class-based generic view

2012-09-26 Thread Germán
Indeed

On Wednesday, September 26, 2012 2:45:32 PM UTC-3, Kurtis wrote:
>
> Sometimes, though, you may need to pass variables to a success url. In 
> that case, I'd use the "get_success_url" method so you can access the 
> 'self' attributes.
>
> On Wed, Sep 26, 2012 at 1:32 PM, Germán  > wrote:
>
>> Just for the record.
>>
>> Since Django 1.4, the best way to set up success_url in class-based 
>> generic views with url names is:
>>
>>> success_url = reverse_lazy('my_url_name')
>>
>>
>> On Wednesday, September 21, 2011 4:53:56 PM UTC-3, Xavier Ordoquy wrote:
>>
>>> Hi,
>>>
>>> You can also use get_success_url for that:
>>>
>>> class ContactView(generic.FormView):
>>> form_class = ContactForm
>>>
>>> def get_success_url(self):
>>> return reverse('contact-sent')
>>>
>>> Regards,
>>> Xavier
>>>
>>> Linovia.
>>>
>>> Le 21 sept. 2011 à 00:08, Daniel P a écrit :
>>>
>>> > Same problem. You'r not alone!
>>> > 
>>> > this is also a solution: 
>>> > http://djangosnippets.org/**snippets/2445/
>>> > 
>>> > -- 
>>> > You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> > To post to this group, send email to django...@googlegroups.com.
>>> > To unsubscribe from this group, send email to django-users...@**
>>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/bm1tU2fvPAAJ.
>>
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/NkYFZU8B5MkJ.
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: Using success_url with reverse() in class-based generic view

2012-09-26 Thread Kurtis Mullins
Sometimes, though, you may need to pass variables to a success url. In that
case, I'd use the "get_success_url" method so you can access the 'self'
attributes.

On Wed, Sep 26, 2012 at 1:32 PM, Germán  wrote:

> Just for the record.
>
> Since Django 1.4, the best way to set up success_url in class-based
> generic views with url names is:
>
>> success_url = reverse_lazy('my_url_name')
>
>
> On Wednesday, September 21, 2011 4:53:56 PM UTC-3, Xavier Ordoquy wrote:
>
>> Hi,
>>
>> You can also use get_success_url for that:
>>
>> class ContactView(generic.FormView):
>> form_class = ContactForm
>>
>> def get_success_url(self):
>> return reverse('contact-sent')
>>
>> Regards,
>> Xavier
>>
>> Linovia.
>>
>> Le 21 sept. 2011 à 00:08, Daniel P a écrit :
>>
>> > Same problem. You'r not alone!
>> >
>> > this is also a solution: 
>> > http://djangosnippets.org/**snippets/2445/
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > To post to this group, send email to django...@googlegroups.com.
>> > To unsubscribe from this group, send email to django-users...@**
>> 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 view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/bm1tU2fvPAAJ.
>
> 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: Using success_url with reverse() in class-based generic view

2012-09-26 Thread Germán
Just for the record.

Since Django 1.4, the best way to set up success_url in class-based generic 
views with url names is:

> success_url = reverse_lazy('my_url_name')


On Wednesday, September 21, 2011 4:53:56 PM UTC-3, Xavier Ordoquy wrote:
>
> Hi,
>
> You can also use get_success_url for that:
>
> class ContactView(generic.FormView):
> form_class = ContactForm
>
> def get_success_url(self):
> return reverse('contact-sent')
>
> Regards,
> Xavier
>
> Linovia.
>
> Le 21 sept. 2011 à 00:08, Daniel P a écrit :
>
> > Same problem. You'r not alone!
> > 
> > this is also a solution: http://djangosnippets.org/snippets/2445/
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> > To post to this group, send email to django...@googlegroups.com
> .
> > To unsubscribe from this group, send email to 
> django-users...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bm1tU2fvPAAJ.
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: Using success_url with reverse() in class-based generic view

2011-09-21 Thread Xavier Ordoquy
Hi,

You can also use get_success_url for that:

class ContactView(generic.FormView):
form_class = ContactForm

def get_success_url(self):
return reverse('contact-sent')

Regards,
Xavier

Linovia.

Le 21 sept. 2011 à 00:08, Daniel P a écrit :

> Same problem. You'r not alone!
> 
> this is also a solution: http://djangosnippets.org/snippets/2445/
> 
> -- 
> 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: Using success_url with reverse() in class-based generic view

2011-09-21 Thread Daniel P
Same problem. You'r not alone!

this is also a solution: http://djangosnippets.org/snippets/2445/

-- 
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: Using success_url with reverse() in class-based generic view

2011-03-28 Thread Rytis Sileika
Had the same issue. Here's what I did in my views.py:

---
from django.utils.functional import lazy

...

class MyDeleteView(DeleteView):
...
success_url = lazy(reverse, str)("success_url_name")
---

Again, I don't know if that's the correct way of doing things, but
worked for me. I think I saw a ticket somewhere that was planning to
implement the lazy_reverse functionality in code Django, but can't
find it, or may be I'm just making things up...




On Mar 22, 10:53 pm, rb  wrote:
> I just ran into this today and was curious. My setup is this:
>
>     class MyGenericView(DeleteView):
>         success_url = reverse('my-name')
>
> This will produce the from the original author. I got around this by
> overriding get_success_url():
>
>     class MyGenericView(DeleteView):
>         def get_success_url(self):
>             return reverse('my-name')
>
> Is this the preferred/proper way to accomplish this? While looking
> around in the tickets I did find this ticket:
>
> http://code.djangoproject.com/ticket/13753
>
> This made me believe that maybe the generic views were using
> redirect() (which can accept names), but I tried setting success_url
> to 'my-name' and it sends an HttpRedirectResponse with that as the
> target. Looking in django.views.generic.edit shows that it is just
> calling HttpRedirectResponse. Should these call redirect() instead of
> HttpRedirectResponse?
>
> Thanks!
>
> Rob
>
> (django 1.3 rc 1 SVN-15894)
>
> On Feb 18, 5:00 pm, jnns  wrote:
>
>
>
> > Hi users,
>
> > I have a CreateView which I'd like to redirect to a custom success_url
> > defined in my URLconf. As I want to stick to the DRY-principle I just
> > did the following:
>
> >    success_url = reverse("my-named-url")
>
> > Unfortunately, this breaks my site by raising an
> > "ImproperlyConfigured: The included urlconf doesn't have any patterns
> > in it". Removing success_url and setting the model's
> > get_absolute_url() to the following works fine:
>
> >    def get_absolute_url(self):
> >        return reverse("my-named-url")
>
> > I could reproduce this with a brand new project/application so I don't
> > think this has something to do with my setup.
>
> > Can anyone confirm this issue?

-- 
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: Using success_url with reverse() in class-based generic view

2011-03-22 Thread rb
I just ran into this today and was curious. My setup is this:

class MyGenericView(DeleteView):
success_url = reverse('my-name')

This will produce the from the original author. I got around this by
overriding get_success_url():

class MyGenericView(DeleteView):
def get_success_url(self):
return reverse('my-name')

Is this the preferred/proper way to accomplish this? While looking
around in the tickets I did find this ticket:

http://code.djangoproject.com/ticket/13753

This made me believe that maybe the generic views were using
redirect() (which can accept names), but I tried setting success_url
to 'my-name' and it sends an HttpRedirectResponse with that as the
target. Looking in django.views.generic.edit shows that it is just
calling HttpRedirectResponse. Should these call redirect() instead of
HttpRedirectResponse?

Thanks!

Rob

(django 1.3 rc 1 SVN-15894)

On Feb 18, 5:00 pm, jnns  wrote:
> Hi users,
>
> I have a CreateView which I'd like to redirect to a custom success_url
> defined in my URLconf. As I want to stick to the DRY-principle I just
> did the following:
>
>    success_url = reverse("my-named-url")
>
> Unfortunately, this breaks my site by raising an
> "ImproperlyConfigured: The included urlconf doesn't have any patterns
> in it". Removing success_url and setting the model's
> get_absolute_url() to the following works fine:
>
>    def get_absolute_url(self):
>        return reverse("my-named-url")
>
> I could reproduce this with a brand new project/application so I don't
> think this has something to do with my setup.
>
> Can anyone confirm this issue?

-- 
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.



Using success_url with reverse() in class-based generic view

2011-02-18 Thread jnns
Hi users,

I have a CreateView which I'd like to redirect to a custom success_url
defined in my URLconf. As I want to stick to the DRY-principle I just
did the following:

   success_url = reverse("my-named-url")

Unfortunately, this breaks my site by raising an
"ImproperlyConfigured: The included urlconf doesn't have any patterns
in it". Removing success_url and setting the model's
get_absolute_url() to the following works fine:

   def get_absolute_url(self):
   return reverse("my-named-url")

I could reproduce this with a brand new project/application so I don't
think this has something to do with my setup.

Can anyone confirm this issue?

-- 
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.