django-views

Handling multiple input values for single html form in django

社会主义新天地 提交于 2019-12-01 16:00:28
I have a html form with 3 inputs and steps buttons. 1 st step user must put first name and press button 1 2 nd step user must put last name and press button 2 3 rd step user must put email and press final button 3 Any time the user press any button then go to next html step. I want to handle inputs in my views.py step by step any time where the user press any button, and not all together in the final submit . I tried this code in views.py to take inputs in django backend but I don't get anything in views.py (if I change button type from button to submit then I get results nut refresh page and

Handling multiple input values for single html form in django

徘徊边缘 提交于 2019-12-01 14:55:23
问题 I have a html form with 3 inputs and steps buttons. 1 st step user must put first name and press button 1 2 nd step user must put last name and press button 2 3 rd step user must put email and press final button 3 Any time the user press any button then go to next html step. I want to handle inputs in my views.py step by step any time where the user press any button, and not all together in the final submit . I tried this code in views.py to take inputs in django backend but I don't get

Filter select field in ModelForm by currently logged in user

隐身守侯 提交于 2019-12-01 14:47:18
I'm trying to display a form (ModelForm) with a select field filtered by currently logged in user. The select field in this case contains a list of categories. I want to display only the categories which "belong" to the currently logged in user. The category field is a foreign key to the IngredienceCategory model. Here is what I've come up with so far but it's giving me an error (unexpected keyword queryset). Any ideas what I'm doing wrong? # models.py class IngredienceCategory(models.Model): name = models.CharField(max_length=30) user = models.ForeignKey(User, null=True, blank=True) class

Passing a list through url in django

吃可爱长大的小学妹 提交于 2019-12-01 14:14:32
I want to pass a list through the url. But when i tried, i got some errors. So how can i do that. Somebody please help me.. this is my view def add_student(request): if request.method == 'POST': student_list = [] student_name = request.POST.getlist('student_name') student_phone = request.POST.getlist('student_phone') zipped = zip(student_name,student_phone) for student_name,student_phone in zipped: student_object = Student( student_name=student_name, student_phone=student_phone ) student_object.save() student_list.append(student_object.id) return HttpResponseRedirect(reverse('students:view

Django - counting model instance views (for a “top entries” app)

和自甴很熟 提交于 2019-12-01 13:59:56
I'm new, and confused. I want to create a module that keeps track of the "top hit" instances of both an article and a blog model. I don't want to touch the code for the article or blog models. Is this a candidate for middleware? looking at the HttpRequest.path ? Middleware looking at request.path is ugly, as it introduces a dependency on the details of the URL patterns you use to display articles and blog posts. If you don't mind this coupling, then you might as well just save the performance hit and do your analysis on webserver log files. ( EDIT : view middleware would be a better option, as

How to load an instance in Django ModelForms

血红的双手。 提交于 2019-12-01 13:21:37
I am using Django's user model. How do I get a Django ModelForm to prepopulate values in a template? I know I have to use the instance for that form, but where am I going wrong below: models.py: class Site(models.Model): user = models.ForeignKey(User, ) site_name = models.CharField(max_length=128, blank=False, null=False) forms.py: class SiteForm(forms.ModelForm): class Meta: model = Site fields = '__all__' views.py: def settings(request): site_profile = Site.objects.get(user=request.user) if request.method == "POST": form = SiteForm( instance=site_profile ) if form.is_valid(): form.save()

Passing a list through url in django

纵然是瞬间 提交于 2019-12-01 12:56:22
问题 I want to pass a list through the url. But when i tried, i got some errors. So how can i do that. Somebody please help me.. this is my view def add_student(request): if request.method == 'POST': student_list = [] student_name = request.POST.getlist('student_name') student_phone = request.POST.getlist('student_phone') zipped = zip(student_name,student_phone) for student_name,student_phone in zipped: student_object = Student( student_name=student_name, student_phone=student_phone ) student

Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']

血红的双手。 提交于 2019-12-01 12:24:19
问题 I created a simple article/blog app. I am having problem in detail view. I created a list view of articles and also created a detail view if someone clicks on one of the acrticle , it takes the to detail view of article . But when i click on one of the articles , i am getting above error stated in the title. It is also pointing the error location to this code {% url "detail" post.id %} which u can see in 44th or 45th line in Error page i posted in the last. I tried lots of thing , none worked

Django: let user download a large file

廉价感情. 提交于 2019-12-01 12:23:27
问题 I am building a private file upload site. Alice uploads a file, Bob downloads it. People other than Alice and Bob should not have access. I was first thinking about giving the file a complex name ( http://domain/download/md5sum.zip ), but I want an expiring link. So something like http://domain/download/tempkey/aaa123/file.zip . This will give me more control over file downloading and logging. I found this: https://stackoverflow.com/a/2900646 . It suggests the following: class RequestHandler

Pagination doesn't accept dict as data - unhashable type

时光总嘲笑我的痴心妄想 提交于 2019-12-01 11:30:53
I'm trying to use Django pagination Pagination Docs . But I'm receiving this error: TypeError at / unhashable type Which is basically because I'm using a dictionary as my object and not a queryset. I would like to know if there is a way to turn my dictionary a hashable object. This is my dict in template: {% for key, values in prodmatrix.items %} <li class="span3"> <div class="product-box"> <span class="sale_tag"></span> <p><a href="{% url 'product_detail' slug=values.3.0 %}"><img src="{{ STATIC_URL }}{{values.1.0}}" alt="" /></a></p> <a href="{% url 'product_detail' slug=values.3.0 %}" class=