This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MIDDLEWARE_CLASSES = ( | |
| ... | |
| 'app.middleware.exceptions.ExceptionMiddleware', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import _get_queryset | |
| from app.exceptions.custom import NotFound | |
| def get_object_or_template(klass, template, *args, **kwargs): | |
| # replacement for django.shortcuts.get_object_or_404() | |
| # allows a template to be supplied instead of a 404 | |
| """ | |
| Uses get() to return an object, or raises a Http404 exception if the object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # get the product or show the not found template | |
| product = get_object_or_template(Product, 'templates/product/not_found.html', pk=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserView(DetailView): | |
| template_name = 'template.html' | |
| #model = User | |
| #context_object_name = 'foo' | |
| def get_object(self): | |
| return get_object_or_404(User, pk=request.session['user_id']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {{ user.id }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| arg_name = 'myarg' | |
| some_method(**{arg_name: 'value'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.views.generic import UpdateView | |
| from django.shortcuts import get_object_or_404 | |
| from django.core.urlresolvers import reverse_lazy | |
| from app.models import Model | |
| from app.forms import Form1, Form2 | |
| class MyView(UpdateView): | |
| template_name = 'template.html' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form action="{% url 'myview' %}" method="post" enctype="multipart/form-data"> | |
| ... | |
| <input type="submit" name="form" value="Submit" /> | |
| </form> | |
| <form action="{% url 'myview' %}" method="post" enctype="multipart/form-data"> | |
| ... | |
| <input type="submit" name="form2" value="Submit" /> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return self.render_to_response(self.get_context_data(form=form)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://developer.apps.yahoo.com/projects | |
| YAHOO_CONSUMER_KEY = 'YOUR-APP-ID' | |
| YAHOO_CONSUMER_SECRET = 'YOUR-APP-SECRET' |