Skip to content

Commit 270ea64

Browse files
committed
adding example code to django page
1 parent 3c03d83 commit 270ea64

17 files changed

+6095
-62
lines changed

content/pages/03-data/06-sqlalchemy.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ implementations.
222222
based on various developers' experiences.
223223

224224

225-
### Open source code for using SQLAlchemy
225+
## Open source code for learning SQLAlchemy
226226
Many open source projects rely on SQLAlchemy. A great way to learn
227227
how to properly work with this tool is to read the code that shows
228228
how those projects use SQLAlchemy. This section alphabetically lists

content/pages/04-web-development/02-django.markdown

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For example,
2121
[template engine](/django-templates.html),
2222
an [object-relational mapper](/object-relational-mappers-orms.html) (ORM),
2323
and [database schema migrations](https://docs.djangoproject.com/en/dev/topics/migrations/)
24-
(as of version 1.7) are all included with the [Django framework](https://pypi.org/project/Django/).
24+
are all included with the [Django framework](https://pypi.org/project/Django/).
2525
Compare that included functionality to the Flask framework which requires a
2626
separate library such as
2727
[Flask-Login](https://flask-login.readthedocs.org/en/latest/)
@@ -315,41 +315,14 @@ to handle these files properly.
315315
shows how to configure Django to load and serve up static and media files, public and private, via an Amazon S3 bucket.
316316

317317

318-
## Open source Django example projects
319-
* [Browser calls with Django and Twilio](https://www.twilio.com/docs/howto/walkthrough/browser-calls/python/django)
320-
shows how to build a web app with Django and
321-
[Twilio Client](https://www.twilio.com/client) to turn a user's web
322-
browser into a full-fledged phone. Pretty awesome!
323-
324-
* [Txt 2 React](https://github.com/mattmakai/txt2react) is a full Django web
325-
app that allows audiences to text in during a presentation with feedback
326-
or questions.
327-
328-
* [Openduty](https://github.com/ustream/openduty) is a website status checking
329-
and alert system similar to PagerDuty.
330-
331-
* [Courtside](https://github.com/myusuf3/courtside) is a pick up sports web
332-
application written and maintained by the author of PyCoder's Weekly.
333-
334-
* These two Django Interactive Voice Response (IVR) system web application
335-
repositories [part 1](https://github.com/phalt/twilio-django-part-1) and
336-
[part 2](https://github.com/phalt/twilio-django-part-2) show you how to
337-
build a really cool Django application. There's also an accompanying
338-
[blog post](https://www.twilio.com/blog/2014/07/build-an-ivr-system-with-twilio-and-django.html)
339-
with detailed explanations of each step.
340-
341-
* [Taiga](https://github.com/taigaio/taiga-back) is a project management
342-
tool built with Django as the backend and AngularJS as the front end.
343-
344-
345318
## Django project templates
346319
Project templates, not to be confused with a
347320
[template engine](/template-engines.html), generate boilerplate code for
348321
a base Django project plus optional libraries that are often used when
349322
developing web applications.
350323

351324
* [Caktus Group's Django project template](https://github.com/caktus/django-project-template)
352-
is Django 1.6+ ready.
325+
is Django 2.2+ ready.
353326

354327
* [Cookiecutter Django](https://github.com/pydanny/cookiecutter-django) is a
355328
project template from Daniel Greenfeld, for use with Audrey Roy's
@@ -364,25 +337,36 @@ developing web applications.
364337
template from Mozilla that is compatible with cookiecutter.
365338

366339

367-
## Django learning checklist
368-
1. [Install Django](https://docs.djangoproject.com/en/dev/topics/install/) on
369-
your local development machine.
340+
## Open source Django example projects
341+
Reading open source code can be useful when you are trying to figure
342+
out how to build your own projects. This is a short list of some
343+
real-world example applications, and many more can be found on the
344+
[Django example projects and code](/django-code-examples.html) page.
370345

371-
1. Work through the initial
372-
["polls" tutorial](https://docs.djangoproject.com/en/dev/intro/tutorial01/).
373-
374-
1. Build a few more simple applications using the tutorial resources found
375-
in the "Django resources" section.
346+
* [Browser calls with Django and Twilio](https://www.twilio.com/docs/howto/walkthrough/browser-calls/python/django)
347+
shows how to build a web app with Django and
348+
[Twilio Client](https://www.twilio.com/client) to turn a user's web
349+
browser into a full-fledged phone. Pretty awesome!
376350

377-
1. Start coding your own Django project with help from the
378-
[official documentation](https://docs.djangoproject.com/en/dev/) and
379-
resource links below. You'll make plenty of mistakes which is critical
380-
on your path to learning the right way to build applications.
351+
* [Openduty](https://github.com/ustream/openduty) is a website status checking
352+
and alert system similar to PagerDuty.
381353

382-
1. Read [2 Scoops of Django](http://www.amazon.com/Two-Scoops-Django-Best-Practices/dp/0981467342)
383-
to understand Django good practices and learn better ways of building
384-
Django web applications.
354+
* [Courtside](https://github.com/myusuf3/courtside) is a pick up sports web
355+
application written and maintained by the author of PyCoder's Weekly.
356+
357+
* These two Django Interactive Voice Response (IVR) system web application
358+
repositories [part 1](https://github.com/phalt/twilio-django-part-1) and
359+
[part 2](https://github.com/phalt/twilio-django-part-2) show you how to
360+
build a really cool Django application. There's also an accompanying
361+
[blog post](https://www.twilio.com/blog/2014/07/build-an-ivr-system-with-twilio-and-django.html)
362+
with detailed explanations of each step.
363+
364+
* [Taiga](https://github.com/taigaio/taiga-back) is a project management
365+
tool built with Django as the backend and AngularJS as the front end.
385366

386-
1. Move on to the [deployment section](/deployment.html) to get your Django
387-
project on the web.
388367

368+
## Open source code to learn Django
369+
There are many open source projects that rely on Django.
370+
One of the best ways to learn how to use this framework is to read
371+
how other projects use it in real-world code. This section lists
372+
these code examples by class and method in Django's code base.

content/pages/04-web-development/03-flask.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ ways to structure your code.
337337
in the JavaScript world.
338338

339339

340-
### Open source code for using Flask
340+
## Open source code for learning Flask
341341
There are many open source projects that rely on Flask to operate.
342342
One of the best ways to learn how to use this framework is to read
343343
how other projects use it in real-world code. This section lists
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
title: django.core.exceptions DisallowedRedirect Example Code
2+
category: page
3+
slug: django-core-exceptions-disallowedredirect-examples
4+
sortorder: 500011098
5+
toc: False
6+
sidebartitle: django.core.exceptions DisallowedRedirect
7+
meta: Python example code for the DisallowedRedirect class from the django.core.exceptions module of the Django project.
8+
9+
10+
DisallowedRedirect is a class within the django.core.exceptions module of the Django project.
11+
12+
13+
## Example 1 from django-oauth-toolkit
14+
[django-oauth-toolkit](https://github.com/jazzband/django-oauth-toolkit)
15+
([project website](http://dot.evonove.it/) and
16+
[PyPI package information](https://pypi.org/project/django-oauth-toolkit/1.2.0/))
17+
is a code library for adding and handling [OAuth2](https://oauth.net/)
18+
flows within your [Django](/django.html) web application and
19+
[API](/application-programming-interfaces.html).
20+
21+
The django-oauth-toolkit project is open sourced under the
22+
[FreeBSD license](https://github.com/jazzband/django-oauth-toolkit/blob/master/LICENSE)
23+
and it is maintained by the developer community group
24+
[Jazzband](https://jazzband.co/).
25+
26+
[**django-oauth-toolkit / oauth2_provider / http.py**](https://github.com/jazzband/django-oauth-toolkit/blob/master/oauth2_provider/./http.py)
27+
28+
```python
29+
# http.py
30+
from urllib.parse import urlparse
31+
32+
~~from django.core.exceptions import DisallowedRedirect
33+
from django.http import HttpResponse
34+
from django.utils.encoding import iri_to_uri
35+
36+
37+
class OAuth2ResponseRedirect(HttpResponse):
38+
status_code = 302
39+
40+
def __init__(self, redirect_to, allowed_schemes, *args, **kwargs):
41+
super().__init__(*args, **kwargs)
42+
self["Location"] = iri_to_uri(redirect_to)
43+
self.allowed_schemes = allowed_schemes
44+
self.validate_redirect(redirect_to)
45+
46+
@property
47+
def url(self):
48+
return self["Location"]
49+
50+
def validate_redirect(self, redirect_to):
51+
parsed = urlparse(str(redirect_to))
52+
if not parsed.scheme:
53+
~~ raise DisallowedRedirect("OAuth2 redirects require a URI scheme.")
54+
if parsed.scheme not in self.allowed_schemes:
55+
~~ raise DisallowedRedirect(
56+
"Redirect to scheme {!r} is not permitted".format(parsed.scheme)
57+
)
58+
59+
60+
61+
## ... source file continues with no further DisallowedRedirect examples...
62+
63+
```
64+

0 commit comments

Comments
 (0)