79👍
✅
Have you tried passing in success_url
? e.g.
CreateView.as_view(model=myModel, success_url="/success/")
or if you want to redirect to a named view:
CreateView.as_view(model=myModel, success_url=reverse('success-url'))
23👍
you can also try to define get_absolute_url in your models. For example
class Something(models.Model):
name = models.CharField(max_length=50, verbose_name='name')
class Meta:
pass
def get_absolute_url(self):
return u'/some_url/%d' % self.id
- [Django]-Django serializer Imagefield to get full URL
- [Django]-'RelatedManager' object is not iterable Django
- [Django]-Django: Get an object form the DB, or 'None' if nothing matches
1👍
Add in views:
def form_valid(self, form):
return self.render_to_response(self.get_context_data(form=form))
- [Django]-How to write setup.py to include a Git repository as a dependency
- [Django]-How to See if a String Contains Another String in Django Template
- [Django]-Is Tornado a replacement to Django or are they complementary to each other?
0👍
views.py/
from django.views.generic import CreateView
from .models import myModel
class createView(CreateView):
model = myModel
fields = ['your fields', ...'']
def get_success_url(self):
return reverse('some_url')
urls.py/ (of your app)
from django.urls import path
from . import views
urlpatterns = [
path('create/', views.createView.as_view(), name='create')
]
- [Django]-Create custom buttons in admin change_form in Django
- [Django]-How can I filter a Django query with a list of values?
- [Django]-Serializing list to JSON
-1👍
class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
model = Post
success_url = '/'
def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
- [Django]-TemplateDoesNotExist – Django Error
- [Django]-Django error: got multiple values for keyword argument
- [Django]-Django: add image in an ImageField from image url
Source:stackexchange.com