Hello,
I've found quite a few answers on this site.
I was a network admin, however these days you have to wear multiple hats and as such I'm learning Python at work and my main source for answers when stuck is of course, the net.
So here is my problem. I'm converting a pre 0.96 app to 1.4 (django/python). I've fixed most of the changes however my code seems right even when compared to others projects. In fact, just the other day I was passing through the views and everything was semi-working but now I just get the following error.
Any help appreciatted, and remember I'm not exactly on target with mots of the technical jargon of django/python yet as an fyi. Cheers if you can help
**UnboundLocalError at /wikicamp/start/edit/
local variable 'page' referenced before assignment
**
===================================================================================================
Traceback:
Environment:
Request Method: GET
Request URL: http://10.3.0.249:8000/wikicamp/start/edit/
Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'wikicamp.wiki')
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 "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/corey/wikicamp/wikicamp/wiki/views.py" in edit_page
24. page.content=['content', 'this is the default']
Exception Type: UnboundLocalError at /wikicamp/start/edit/
Exception Value: local variable 'page' referenced before assignment
====================================================================================================
views
from wikicamp.wiki.models import Page
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.shortcuts import HttpResponseRedirect
from django import forms
import markdown
import htmllib
from django.template import RequestContext, loader
from django.core.context_processors import csrf
#create your views here
def view_page(request, page_name):
c = {}
try:
page = Page.objects.get(pk=page_name)
content=page.content
except Page.DoesNotExist:
content = page.content
return render_to_response("create.html", {"page_name":page_name}, context_instance=RequestContext(request))
return render_to_response("view.html", {"page_name":page_name, "content":content}, context_instance=RequestContext(request))
def edit_page(request, page_name):
c = {}
page.content=['content', 'this is the default']
page.name=['name', 'this is the default']
try:
page = Page.objects.get(pk=page_name)
content = page.content
except Page.DoesNotExist:
return render_to_response("edit.html", {"page_name":page_name, "content":content}, context_instance=RequestContext(request))
def save_page(request, page_name):
c = {}
content = request.POST['content']
try:
page = Page.objects.get(pk=page_name)
content = request.GET['content']
page.content = ['content']
except Page.DoesNotExist:
Page = Page(name=page_name, page_content=content)
return HttpResponseRedirect ("wikicamp/" + page_name + "/")
=============================================================================================
models:
class Page(models.Model):
name = models.CharField(max_length="20", primary_key=True)
content = models.TextField(blank=True)
def __unicode__(self):
return self.name