django-views

form wizard initial data for edit not loading properly in Django?

☆樱花仙子☆ 提交于 2019-12-20 07:20:03
问题 I have a three page form-list coming out of a single model. I could save the model first time, but when I want to edit the model, only the first form shows the initial value, subsequent forms does not show the initial data. but when I print the initial_dict from views, I can see all the initial views correctly. I followed this blog on form wizard. Here is my model.py: class Item(models.Model): user=models.ForeignKey(User) price=models.DecimalField(max_digits=8,decimal_places=2) image=models

Implementing http404 in django

♀尐吖头ヾ 提交于 2019-12-20 06:49:09
问题 Implementing page not found in django and have looked at the documentation 404 I do not get a page not found error as yet what ami doing here In my code in urls i have done the following, url(r'^$', 'site_config.views.pagenotfound') from django.http import Http404 def pagenotfound(request): return render_to_response('polls/pagenotfound.html', {}) 回答1: The way you handle 404 and 500 in django is: by default, in the templates directory, create a 404.html If you need a custom handler, just add

Limit values in the modelformset field

♀尐吖头ヾ 提交于 2019-12-20 06:46:02
问题 I've been trying to solve this problem for a couple of days now, getting quite desperate. See the commented out code snippets for some of the things I've tried but didn't work. Problem: How can I limit the values in the category field of the IngredientForm to only those belonging to the currently logged in user? views.py @login_required def apphome(request): IngrFormSet = modelformset_factory(Ingredient, extra=1, fields=('name', 'category')) # Attempt #1 (not working; error:

get_success_url() takes exactly 3 arguments (2 given)

泪湿孤枕 提交于 2019-12-20 06:37:27
问题 every one ,, I am using django-registration-redux (1.4) for my django registration(django 1.8),,however ,,when never I registered the web will show the error ,,but the views.py in form_valid, line 43 it is the editing function,,it seems not about the register?? views.py @login_required def edit_thing(request, slug): # grab the object... thing = ProductsTbl.objects.get(slug=slug) if thing.user != request.user: raise Http404 # set the form we're using... form_class = ProductsTblForm if request

template tag inside object TextField

喜欢而已 提交于 2019-12-20 06:28:25
问题 I need custom template tag inside model.TextField value. Value from the object text field have something like "lorem ipsum dolor {% mytag %}" but "mytag" is not rendered as template tag. It is registered in the library as tag and loaded on the page and I have {{ object.textfield|safe }} filter. Is it possible at all? 回答1: As Django's template engine can easily be used anywhere in your code you should be able to do something like this: from django.template import Context, Template rendered =

Django Ajax Form submit wrongly redirect to another page

半城伤御伤魂 提交于 2019-12-20 06:28:23
问题 When I use ajax to submit a comment form in Django,the page will redirect to a blank page shows me the success data: {"status":"success", "msg":"添加成功"} ,but not stay in current page.I want the page stay in current page and show me the new comment. Here is my update_comment view: def update_comment(request, news_pk): news = get_object_or_404(News, id=news_pk) comment_form = CommentForm(request.POST or None) if request.method == 'POST' and comment_form.is_valid(): if not request.user.is

ajax with django forms

萝らか妹 提交于 2019-12-20 06:26:26
问题 can i add the ajax code with django? i have created a simple registraion form that have 5 fields . i wish to disply the each fields in different pages but in a single window . it means by using next button 5 pages want to disply in a single window. same time all content of each page i want add to my database. is this possible in django with ajax.. my codes are as follows : #view from django.shortcuts import render_to_response from registration.models import UserDetails from forms import

Django QuerySet returns nothing

偶尔善良 提交于 2019-12-20 06:12:13
问题 I have a list of countries, they all have there own url www.example.com/al/ for example. There is a list of cities for every country but the object_list is empty My View: class CityOverview(generic.ListView): template_name = 'shisha/pages/country_index.html' model = City def get_queryset(self, *args, **kwargs): country_id = self.kwargs.get('country_id') return City.objects.filter(country__name=country_id) My Model: class Country(models.Model): COUNTRY_CHOICES = ( ('al', 'Albania'), ('ad',

How to create link for one of the category in Django

做~自己de王妃 提交于 2019-12-20 05:50:43
问题 I'm coding a news website.I have 'category' in News model. I want to get all the news in one of the categories named 'opinion' in my index.html. And create detail page link for each of them. I can the title ,author, etc of the news mentioned above .But my brain really junks,I don't know how to create a link points to opinion_new.html or news_detail.htlm for each of them.I have a link for regular news to point to news_detail.htlm. If you don't quite understand what I'm asking, please also read

Ajax not work in Django post

杀马特。学长 韩版系。学妹 提交于 2019-12-20 05:41:33
问题 I'm trying to use ajax in Django to post comment in a news website.However it doesn't work. When I click the submit button,it still refreshes the page and make no difference like no ajax. I'm really new in Django and Ajax.Any friend can help me solve it? Here is my view.py: def newsDetailView(request, news_pk): news = News.objects.get(id=news_pk) title = news.title author = news.author_name add_time = news.add_time content = news.content category = news.category tags = news.tag.annotate(news