python - Convert argument to string -


never work struct before. when hire developer work, used this, doesn't work. , developer doesn't answer... please, can problem?

from views.py, can see below, got error struct() argument 1 must string, not unicode in 'invid': str(struct.unpack('=h', urandom(2))[0]),. so, how convert string?

@login_required def userprofile(request, username):      extra_context = dict()      if request.post:         user_form = userform(request.post, instance=request.user)         user_profile = userprofileform(request.post, request.files,                                        instance=request.user.profile)         if user_form.is_valid():             user_form.save()         if user_profile.is_valid():             user_profile.save()     else:         user_form = userform(             instance=request.user,             initial={                 'first_name': request.user.first_name,                 'last_name': request.user.last_name,                 'email': request.user.email,             })         user = request.user         profile = user.profile         user_profile = userprofileform(instance=profile)      extra_context['user_form'] = user_form     extra_context['user_profile'] = user_profile     extra_context['robo_form'] = robokassaform(initial={         'userid': request.user.id,         'outsum': 1000,         'invid': struct.unpack('=h', urandom(2))[0],         'email': request.user.email,     })      return render_to_response('profile.html', extra_context, context_instance=requestcontext(request)) 

struct.unpack('=h', urandom(2))[0] dumb. generate integer in readable way:

'invid': random.randrange(2**16), 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -