Hi,
  I have an error that is stumping me.  It may be a django or python
issue and nothing to do with webfaction butI have been working on it
for a while now and don't know where else to turn. I am fairly new to
Python and Django so it might be obvious to someone more experienced.
I have a global variable defined in a file called globvars.py:

Code:

alias = {'fake_username':''}

Then I have a view where I try and set the variable based upon
whatever the user enters as a username(I know this is a little weird
but this site is only for friends and family so I just figured they
could use one account and enter any name they want to enter with and I
would change it to generic_user which I have set up in my admin
page).  Looking back it would have been easier to just implement some
easy way of registering everyone, but I already have this mostly
working. Anyway, the global gets set and then I want to save their
username they entered with to use in the blog when they decide to
comment.

Code:

from mysite.globvars import *

def my_login_view(request, template_name='registration/
standard_login.html'):
    "Displays the login form and handles the login action."
    if request.POST:
        request.session.set_test_cookie()
        if request.session.test_cookie_worked():
            username = 'generic_user'
            alias['fake_username'] = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                request.session.delete_test_cookie()
                return HttpResponseRedirect('/')
            else:
                return render_to_response('registration/
auth_failed_login.html', context_instance=RequestContext(request))
        else:
            return render_to_response('registration/
cookie_failed_login.html', context_instance=RequestContext(request))
    return render_to_response(template_name,
context_instance=RequestContext(request))

I am trying to pass the alias global that I captured at login into the
object_detail_wrapper via extra_context as you can see below:
Code:

from django.conf.urls.defaults import *
from mysite import views
from mysite.blog.models import Entry

blog_dict_welcome = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    'template_name': 'welcome.html',
}

blog_dict_detail = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    'extra_context': { 'fake_username': '' }
    }


urlpatterns = patterns('',
    (r'^$', views.home, blog_dict_welcome),
    (r'^time/$', views.current_datetime),
    (r'^time/plus/(\d{1,2})/$', views.hours_ahead),
    (r'^admin/', include('django.contrib.admin.urls')),
    (r'^search/$', 'mysite.books.views.search'),
    (r'^contact/$', 'mysite.books.views.contact'),
    #(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/home/blah/Documents/web_design/djcode/
static_media'}),
    (r'^blog/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?
P<slug>[-\w]+)/$', views.object_detail_wrapper, dict(blog_dict_detail,
slug_field='slug')),
    #(r'^$', 'django.views.generic.date_based.archive_index',
blog_dict_welcome),
    (r'^comments/', include('django.contrib.comments.urls.comments')),
    (r'^accounts/login/$',  views.my_login_view),
    (r'^accounts/logout/$', views.my_logout_view),

)

These are the other functions in the views.py file:

Code:

#require login for this page
@login_required
def home(*args, **kwargs):
    return archive_index(*args, **kwargs)


@login_required
def object_detail_wrapper(*args, **kwargs):
    kwargs['extra_context']['fake_username'] = alias['fake_username']
    return object_detail(*args, **kwargs)

So, this all works fine on the development server on my laptop using
the latest django trunk, but on webfactions server it doesn't work all
of the time.  Sometimes when I access my object_detail( by the way I
also wrote my own freeform.html in templates/comments and modified it
to use the fake_username as the person_name) it shows the name and
then if I use Ctrl-R in firefox to refresh the page it shows nothing.
If I hit Ctrl-R again it puts my name back, and so on. It's like there
there are two copies of the global that I am accessing. I can't figure
this out.  Any ideas? Thanks so much!

csmithmaui

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to