5 ms·
Great to see Mozilla supporting Django. But isn't the official Django tutorial cover all of this, Why not just link to it?
by molly0 10y ago
Great to see Mozilla supporting Django. But isn't the official Django tutorial cover all of this, Why not just link to it?
- diminoten 10y agoThis is an order of magnitude more detailed, IMO.
- vivekd 10y agoDjango's basic tutorial is great to get started, but once you get into the nitty gritty I find myself often going to stacks rather than the docs to get the information I need because the docs get kinda sparse. One example is if you want to forgo modelforms and pass the information from the forms to the model manually through your view (for example because you want to manipulate the information before passing it to the database). I couldn't find anything in the tutorial that gave clear instructions on this and had to go to stacks to find an example. Maybe the solution is simple and obvious for most experienced programmers, but ordinarily the django tutorial explains things clearly so even newbees like me can get into it so it was disappointing that this was not done in this instance. Another example is sessions, here is the sessions in the official django docs - https://docs.djangoproject.com/en/1.10/topics/http/sessions/ https://docs.djangoproject.com/en/1.10/topics/http/sessions/ it's great on how to configure and set up sessions, but as soon as you get to how you use sessions in views it gets vague, confusing and way too sparse for what its trying to explain. I didn't know how to use sessions after reading it.
- Lxr 10y agoI think the Django docs are pretty comprehensive in the scheme of things. Maybe not perfect but better than average in this space.
- vivekd 10y agoI would definitely agree with that, the first we program I tried to work with was PHP and I think I might have given up on programming altogether had I not discovered django with it's much better documentation. I appreciate what they have done and appreciate the time and effort the Django team put into their documentation, but more is always better and I think other independent contributions on how to use django are also needed, especially since most of the published books you can find on how to use django are out of date
- ubercore 10y agoI'm not trying to be argumentative, but to me https://docs.djangoproject.com/en/1.10/topics/http/sessions/#using-sessions-in-views https://docs.djangoproject.com/en/1.10/topics/http/sessions/... is pretty thorough. Did you come into Django knowing Python already?
- chubuntu 10y agoHow did you solve the problem of bypassing modelforms? Same roadblock here...
- vivekd 10y agoyou reference the model in the view and then tell the view to save it directly to the model using the "model = form field" type syntax to assign value and then .save() method to save. In the form field you are saving from, you write the form field value and then an empty space where the input value goes sort of like "form.cleaned_data.get("field name", " "). The second blank ""is the empty space where the field value goes. The claned_data is django's internal form validator. That sounds confusing so I'll give an example This is what your views would look like from django.shortcuts import render from sample.models import Test from sample.forms import TestForm def Example(request): if request.method == 'POST': form = TestForm(request.POST) if form.is_valid(): testmodel = Test() testmodel.modelfield1 = form.cleaned_data.get('formfield1','') testmodel.modelfield2 = form.cleaned_data.get('formfield2','') testmodel.save() return render(request, 'sample/nextpage.html') else: form =TestForm context_data = {'form':form} return render(request, 'sample/testformpage.html', context_data)
- voyou 10y ago"The second blank ""is the empty space where the field value goes." I'm not sure I understand what you're saying here, but I don't think this is right. cleaned_data is a dictionary, and so the second argument to get is a default value to use if there is no value corresponding to the key. So, in your example, if there's no value for "formfield1" in cleaned_data, it would return a string with a space in. This is probably not what you want to do. cleaned_data will always contain values for declared form fields, so the only way the default would be used is if you've made a mistake in specifying the key (for instance, if there's a typo and you've written 'formfeild1' instead of 'formfield1'). If you've made that kind of mistake, you don't want the program to continue using a single space instead of the valid data (you'll lose data) - you want the program to report that there's something wrong. So I think you should probably use form.cleaned_data['formfield1'] which will do the same thing if formfield1 is a real field name specified in the form, but will raise an exception if it isn't.
- acjohnson55 10y agoYou should consider contributing to the docs if there are things you think could be clearer or more thorough. It's a great way to get your feet wet in OSS, and really helps the next person.
- farabove 10y agoMozilla are really explaining the details between the lines here.