python - Missing META attribute when subclassing the base Django generic view? -
i'm trying subclass base of operations generic view object provided django can command rendering of view still utilize cleaner class-based view method instead of mapping function.
this view far:
from django.views.generic.base import view django.shortcuts import render account.forms import userform, userprofileform class registerview(view): def get(request, *args, **kwargs): user_form = userform() profile_form = userprofileform() homecoming render(request, 'account/register.html', {'user_form': user_form, 'profile_form': profile_form}) def post(request, *args, **kwargs): pass
when seek navigate url view error django:
attributeerror @ /account/register/ 'registerview' object has no attribute 'meta' request method: request url: http://localhost:8000/account/register/ django version: 1.4.3 exception type: attributeerror exception value: 'registerview' object has no attribute 'meta' exception location: c:\python27\lib\site-packages\django\core\context_processors.py in debug, line 35 python executable: c:\python27\python.exe python version: 2.7.3 environment: request method: request url: http://localhost:8000/account/register/ django version: 1.4.3 python version: 2.7.3 installed applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'account') installed middleware: ('django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware') traceback: file "c:\python27\lib\site-packages\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) file "c:\python27\lib\site-packages\django\views\generic\base.py" in view 48. homecoming self.dispatch(request, *args, **kwargs) file "c:\python27\lib\site-packages\django\views\generic\base.py" in dispatch 69. homecoming handler(request, *args, **kwargs) file "c:\project\account\views.py" in 49. homecoming render(request, 'account/register.html', {'user_form': user_form, 'profile_form': profile_form}) file "c:\python27\lib\site-packages\django\shortcuts\__init__.py" in render 40. context_instance = requestcontext(request, current_app=current_app) file "c:\python27\lib\site-packages\django\template\context.py" in __init__ 176. self.update(processor(request)) file "c:\python27\lib\site-packages\django\core\context_processors.py" in debug 35. if settings.debug , request.meta.get('remote_addr') in settings.internal_ips: exception type: attributeerror @ /account/register/ exception value: 'registerview' object has no attribute 'meta'
the documentation doesn't specify "meta attribute" when subclassing generic views, i'm not sure i'm doing wrong or if permitted usage of base of operations generic view.
i'm bit new (serious) python programming , django, please forgive me if i'm missing obvious this.
remember class: you've missed self
argument in definitions of get
, post
:
def get(self, request, *args, **kwargs):
python django django-views
No comments:
Post a Comment