Answers for "django reverse_lazy"

3

django reverse

from django.urls import reverse

def myview(request):
    return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
Posted by: Guest on October-09-2020
0

import reverse_lazy

from django.urls import reverse_lazy
Posted by: Guest on October-12-2020
0

django deleteview class

##### views.py #####
from django.urls import reverse_lazy
from django.views.generic.edit import DeleteView
from myapp.models import Author

class AuthorDelete(DeleteView):
    model = Author
    success_url = reverse_lazy('author-list')
    
##### author_confirm_delete.html #####
<form method="post">{% csrf_token %}
    <p>Are you sure you want to delete "{{ object }}"?</p>
    <input type="submit" value="Confirm">
</form>
Posted by: Guest on April-17-2020
0

where to import reverse_lazy in django

from django.shortcuts import reverse 
OR
from django.urls import reverse,reverse_lazy
Posted by: Guest on August-12-2021
-1

django reverse lazy

class NewJobCBV(LoginRequiredMixin, CreateView):
    template_name = 'company/job.html'
    form_class = newJobForm
    # success_url = reverse_lazy('newJob')

    def get_success_url(self, **kwargs):
        return reverse("newJob")
Posted by: Guest on November-12-2020
-2

django imagefield modelform

@login_required
def Product_Adder_View(request):
    
    if request.method == 'POST':
        Prdct_form = ProductForm(request.POST, request.FILES)
        if Prdct_form.is_valid():
            Prdct_form.save()
            return HttpResponseRedirect(reverse('basic_app:Product_added'))
        else:
            raise('Not Valid Form')
    else:
        Prdct_form = ProductForm()
    return render(request, 'basic_app/product_adding.html', context={'Prdct_form':Prdct_form})
  
  
  # in form ModelForm
  class ProductForm(forms.ModelForm):
    # category = forms.ModelChoiceField(queryset= PCategory.order_by('cat_name'))
    category = forms.ModelChoiceField(queryset= PCategory.objects.all())
    product_image = forms.ImageField()
    class Meta:
        model = Products
        fields = ("category", "product_name", "product_image")
Posted by: Guest on April-05-2020

Python Answers by Framework

Browse Popular Code Answers by Language