PageSourceSearch

http://django-vanilla-views.org/migration/base-views

html django-vanilla-views.org collected 2026-10-08 20:00:34 UTC 11,006 bytes, 218 lines download raw bytes

1<!DOCTYPE html>
2<html lang="en">
3<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4    <meta charset="utf-8">
5    <title>Django Vanilla Views - Migration Guide</title>
6    <link href="http://django-vanilla-views.org/img/favicon.ico" rel="icon" type="image/x-icon">
7    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8    <meta name="description" content="Django, CBV, GCBV, Generic class based views, Migration Guide">
9    <meta name="author" content="Tom Christie">
10
11    <!-- Le styles -->
12    <link href="http://django-vanilla-views.org/css/prettify.css" rel="stylesheet">
13    <link href="http://django-vanilla-views.org/css/bootstrap.css" rel="stylesheet">
14    <link href="http://django-vanilla-views.org/css/bootstrap-responsive.css" rel="stylesheet">
15    <link href="http://django-vanilla-views.org/css/default.css" rel="stylesheet">
16
17    
17<script>
vendor: 359 bytes, lines 17-23
17
18      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
19      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
20      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
21      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
22
23      ga('create', '
23UA-27795084-3
vendor: 67 bytes, lines 23-26
23', 'django-vanilla-views.org');
24      ga('send', 'pageview');
25
26    
26</script>
26
27  </head>
28  <body onload="prettyPrint()" class="base-views-page">
29
30  <div class="wrapper">
31
32    <div class="navbar navbar-inverse navbar-fixed-top">
33      <div class="navbar-inner">
34        <div class="container-fluid">
35            <a class="repo-link btn btn-primary btn-small" href="https://github.com/tomchristie/django-vanilla-views/tree/master">GitHub</a>
36            <a class="repo-link btn btn-inverse btn-small " href="../migration/model-views">Next <i class="icon-arrow-right icon-white"></i></a>
37            <a class="repo-link btn btn-inverse btn-small " href="../api/model-views"><i class="icon-arrow-left icon-white"></i> Previous</a>
38            <a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
39          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
40            <span class="icon-bar"></span>
41            <span class="icon-bar"></span>
42            <span class="icon-bar"></span>
43          </a>
44          <a class="brand" href="http://django-vanilla-views.org">Django Vanilla Views</a>
45          <div class="nav-collapse collapse">
46            <ul class="nav">
47              <li><a href="http://django-vanilla-views.org">Home</a></li>
48              <li class="dropdown">
49                <a href="#" class="dropdown-toggle" data-toggle="dropdown">API Guide <b class="caret"></b></a>
50                <ul class="dropdown-menu">
51                  <li><a href="http://django-vanilla-views.org/api/base-views">Base Views</a></li>
52                  <li><a href="http://django-vanilla-views.org/api/model-views">Model Views</a></li>
53                </ul>
54              </li>
55              <li class="dropdown">
56                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Migration Guide <b class="caret"></b></a>
57                <ul class="dropdown-menu">
58                  <li><a href="http://django-vanilla-views.org/migration/base-views">Base Views</a></li>
59                  <li><a href="http://django-vanilla-views.org/migration/model-views">Model Views</a></li>
60                </ul>
61              </li>
62              <li class="dropdown">
63                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
64                <ul class="dropdown-menu">
65                  <li><a href="http://django-vanilla-views.org/topics/frequently-asked-questions">Frequently Asked Questions</a></li>
66                  <li><a href="http://django-vanilla-views.org/topics/django-braces-compatibility">Django Braces Compatibility</a></li>
67                  <li><a href="http://django-vanilla-views.org/topics/django-extra-views-compatibility">Django Extra Views Compatibility</a></li>
68                  <li><a href="http://django-vanilla-views.org/topics/release-notes">Release Notes</a></li>
69                </ul>
70              </li>
71            </ul>
72            <ul class="nav pull-right">
73              <!-- TODO
74              <li class="dropdown">
75                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Version: 2.0.0 <b class="caret"></b></a>
76                <ul class="dropdown-menu">
77                  <li><a href="#">Trunk</a></li>
78                  <li><a href="#">2.0.0</a></li>
79                </ul>
80              </li>
81            -->
82            </ul>
83          </div><!--/.nav-collapse -->
84        </div>
85      </div>
86    </div>
87
88    <div class="body-content">
89      <div class="container-fluid">
90
91<!-- Search Modal -->
92<div id="searchModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
93  <div class="modal-header">
94    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
95    <h3 id="myModalLabel">Documentation search</h3>
96  </div>
97  <div class="modal-body">
98    <!-- Custom google search -->
99    
99<script>
100      (function() {
101        var cx = '015016005043623903336:vem911c4guk';
102        var gcse = document.createElement('script');
103        gcse.type = 'text/javascript';
104        gcse.async = true;
105        gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
106            '//www.google.com/cse/cse.js?cx=' + cx;
107        var s = document.getElementsByTagName('script')[0];
108        s.parentNode.insertBefore(gcse, s);
109      })();
110    </script>
110
111    <gcse:search></gcse:search>
112  </div>
113  <div class="modal-footer">
114    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
115  </div>
116</div>
117
118        <div class="row-fluid">
119
120          <div class="span3">
121            <!-- TODO
122            <p style="margin-top: -12px">
123              <a class="btn btn-mini btn-primary" style="width: 60px">&laquo; previous</a>
124              <a class="btn btn-mini btn-primary" style="float: right; margin-right: 8px; width: 60px;">next &raquo;</a>
125            </p>
126          -->
127            <div id="table-of-contents">
128              <ul class="nav nav-list side-nav well sidebar-nav-fixed">
129                <li class="main"><a href="#migration-guide">Migration Guide</a></li>
130<li><a href="#base-views">Base Views</a></li>
131
132              </ul>
133            </div>
134          </div>
135
136          <div id="main-content" class="span9">
137            <h1 id="migration-guide">Migration Guide</h1>
138<h2 id="base-views">Base Views</h2>
139<p>This document provides the complete set of API changes between Django's existing basic generic views and the corresponding <code>django-vanilla-views</code> implementations.</p>
140<p>It covers <code>RedirectView</code>, <code>TemplateView</code> and <code>FormView</code>.  For the model views please <a href="model-views">see here</a>.</p>
141<p>Wherever API points have been removed, we provide examples of what you should be using instead.</p>
142<p>Although a large amount of API has been removed, the functionality that the views provide should be identical to Django's existing views.  If you believe you've found some behavior in Django's generic class based views that can't also be trivially achieved in <code>django-vanilla-views</code>, then please <a href="https://github.com/tomchristie/django-vanilla-views/issues">open a ticket</a>, and we'll treat it as a bug.</p>
143<hr />
144<h4 id="initial-prefix-get_initial-get_prefix-get_form_kwargs"><code>initial</code>, <code>prefix</code>, <code>get_initial()</code>, <code>get_prefix()</code>, <code>get_form_kwargs()</code></h4>
145<hr />
146<p><strong>These are all removed</strong>.  If you need to override how the form is intialized, just override <code>get_form()</code>.</p>
147<p>For example, instead of this:</p>
148<pre class="prettyprint lang-py"><code>def get_form_kwargs(self):
149    kwargs = super(AccountEditView, self).get_form_kwargs
150    kwargs['user'] = self.request.user
151    return kwargs
152</code></pre>
153<p>You should write this:</p>
154<pre class="prettyprint lang-py"><code>def get_form(self, data, files, **kwargs):
155    kwargs['user'] = self.request.user
156    return AccountForm(data, files, **kwargs)
157</code></pre>
158<hr />
159<h4 id="content_type-response_cls"><code>content_type</code>, <code>response_cls</code></h4>
160<hr />
161<p><strong>These are removed</strong>.  If you need to customize how responses are rendered, you should override <code>render_to_response()</code>.</p>
162<pre class="prettyprint lang-py"><code>def render_to_response(context):
163    return JSONResponse(self.request, context)
164</code></pre>
165<p>If you needed to override the content type, you might write:</p>
166<pre class="prettyprint lang-py"><code>def render_to_response(context):
167    template = self.get_template_names()
168    return TemplateResponse(self.request, template, context, content_type='text/plain')
169</code></pre>
170<hr />
171<h4 id="get_form"><code>get_form()</code></h4>
172<hr />
173<p><strong>This is refactored</strong>, instead of taking a single <code>form_class</code> argument it instead takes the form <code>data</code> and <code>files</code> arguments, plus optional extra keyword arguments.  This results in a simpler, more direct control flow in the implementation.</p>
174<p>Instead of this in your views:</p>
175<pre class="prettyprint lang-py"><code>form_cls = self.get_form_class()
176form = self.get_form(form_cls)
177</code></pre>
178<p>You should write this:</p>
179<pre class="prettyprint lang-py"><code>form = self.get_form(request.DATA, request.FILES)
180</code></pre>
181          </div><!--/span-->
182        </div><!--/row-->
183      </div><!--/.fluid-container-->
184    </div><!--/.body content-->
185
186      <div id="push"></div>
187  </div><!--/.wrapper -->
188
189  <footer class="span12">
190    <p>Sponsored by <a href="http://dabapps.com/">DabApps</a>.</a></p>
191  </footer>
192
193    <!-- Le javascript
194    ================================================== -->
195    <!-- Placed at the end of the document so the pages load faster -->
196    
196<script src="http://django-vanilla-views.org/js/jquery-1.8.1-min.js"></script>
196
197    
197<script src="http://django-vanilla-views.org/js/prettify-1.0.js"></script>
197
198    
198<script src="http://django-vanilla-views.org/js/bootstrap-2.1.1-min.js"></script>
198
199    
199<script>
200      //$('.side-nav').scrollspy()
201      var shiftWindow = function() { scrollBy(0, -50) };
202      if (location.hash) shiftWindow();
203      window.addEventListener("hashchange", shiftWindow);
204
205      $('.dropdown-menu').on('click touchstart', function(event) {
206        event.stopPropagation();
207      });
208
209      // Dynamically force sidenav to no higher than browser window
210      $('.side-nav').css('max-height', window.innerHeight - 130);
211
212      $(function(){
213        $(window).resize(function(){
214          $('.side-nav').css('max-height', window.innerHeight - 130);
215        });
216      });
217    </script>
217
218</body></html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.