Upgrade to Pro — share decks privately, control downloads, hide ads and more …

8 Reasons Why Learning Django is Hard (Django B...

8 Reasons Why Learning Django is Hard (Django Boston - January 2019)

The Django web framework famously has somewhat of a learning curve, but if you understand the common challenges to learning it properly, you'll progress much more quickly.

Avatar for William S. Vincent

William S. Vincent

January 16, 2019
Tweet

More Decks by William S. Vincent

Other Decks in Technology

Transcript

  1. 8 Reasons Why Learning Django is Hard William Vincent Django

    Boston (January 2019) https://wsvincent.com
  2. Tutorials • DjangoGirls - blog with FBVs • Django for

    Beginners - 3 apps with CBVs • Mozilla - lending library app • SimpleIsBetterThanComplex - beginner’s guide 7-part series • RealPython - growing list of tutorials, some out-of-date • Official Polls tutorial - for intermediate web developers
  3. Blog - Models # models.py class Post(models.Model): title = models.CharField(max_length=200)

    author = models.ForeignKey( 'auth.User', on_delete=models.CASCADE, ) body = models.TextField()
  4. Blog - Views # views.py from django.views.generic import DetailView from

    .models import Post class BlogDetailView(DetailView): model = Post template_name = 'post_detail.html'
  5. Blog - URLs # urls.py from django.urls import path from

    .views import BlogDetailView urlpatterns = [ path('post/<int:pk>/', BlogDetailView.as_view(), name='post_detail'), ]
  6. Blog - Template # post_detail.html {% extends 'base.html' %} {%

    block content %} <div class="post-entry"> <h2>{{ post.title }}</h2> <p>{{ post.author }}</p> <p>{{ post.body }}</p> </div>
  7. Example 1 - Templates App-level └── blog_project ├── posts ├──

    templates ├── pages ├── post_detail.html Project-level └── blog_project ├── posts ├── templates ├── post_detail.html
  8. Example 2 - Settings files • Two Scoops advocated using

    local, dev, and production settings.py files • Environment variables the more modern approach but not well documented yet. • Most beginners are super confused by this!
  9. Example 3 - About Page 3 ways # views.py from

    django.shortcuts import render def about_page_view(request): return render(request, 'about.html')
  10. Example 3 - About Page 3 ways # views.py from

    django.views.generic import TemplateView class AboutPageView(TemplateView): template_name = 'about.html'
  11. Example 3 - About Page 3 ways # urls.py from

    django.views.generic import TemplateView urlpatterns = [ path(‘about/', TemplateView.as_view(template_name=’about.html’), name='about'), ]
OSZAR »