Learn web development: Django Web Framework(developer.mozilla.org) |
Learn web development: Django Web Framework(developer.mozilla.org) |
Clearly it depends what your use-cae is, but for a large class of apps that you'd build with Django it feels just right for me: http://intercoolerjs.org/2016/10/05/how-it-feels-to-learn-in...
My apologies if you have street cred in the field, but I don't know you, so have no reason to trust your recommendation. Please tell me what makes this particular project better than any alternatives.
The setup is not really straight forward, and generally I have problems mixing django static files in my .scss url() , so this is far from perfect. I'm using it with a main .ts file that requires various components based on the class of body tag, so I can use this in simple reload request use case. Also I've complicated things a little so my webpack bundles are collected as other static files and my static template tag also works.
But yeah, using react in typescript and sass in this way for the frontend has accelerated my development a lot.
the vast majority of websites that need indexing should not need JS to create the html.
the vast majority of web apps that benefit from being SPAs are behind some form of login/auth and so do not need indexing.
yet there's this obsession with writing SPAs that can be pre-rendered for better indexing. i only assume this is a solution to the desire of using nodejs and javascript as a server-side language regardless of merit.
Since the html output is minimal, presumably you require something like python-react that pipes the output through a nodejs server?
Presumably building the same in a React SPA using Django, that would also mean maintaining the routing system in two different frameworks at once?
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/
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.
The timing of this article couldn't have been better. Now I've got my weekend cut out :)
If you want to make a solid, stable web-app Django is a perfect backend.
As someone who came to Django quite late, I cannot stress enough how coding in Django is refreshing. Yes it's not about microservices nor it bring all the trendy technologies that we all hear about.
And that's just fine, you get things done with it and at the end of the day this is what matters.
As far as I can tell, no file, hidden or otherwise, is left in the outer folder.
from .foo_models import *
from .bar_models import *
in your __init__.py
There are moments when going through docs where way too many assumptions are made about what I know. This is where prerequisites and objectives really help out. I know what I am getting into before grokking.
The learning sites from MDN are very good. ;-)
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
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)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.I just tried your solution with cleaned_data["formfield1"] instead of cleaned_data("formfield1","") and it didn't work for me, it came back with the following error message when I submitted the form:
>'builtin_function_or_method' object is not subscriptable
I think you have to have the empty quotes after the form field and I think that's what's capturing the user input
so here "form.cleaned_data("formfield1","") seems to be telling django the form name and then the second field is where the associated user input goes which is then passed to the model.
Works also with models with m2m fields with Form.save_m2m().
so it seems the right way is form.cleaned_data.get('formfieldvalue')
or
form.cleaned_data[formfieldvalue']
if you don't want to use get