Click here to Skip to main content
15,031,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I explain my problem as better as I can:

I have a program written in 3 modules. I want to save some data from a site (Now I'm using a local host to make tests) to some variables and show some variables' value in the index page in this way:

1.- [Script: Text_Variable] <-- [localhost: ask_for_text]
2.- [Script: Menu_Options] --> [localhost: show_menu]
3.- [Script: Option_Variable] <-- [localhost: user_option]
4.- [Script: Response_Variable] --> [localhost: show_response]

Depending the value of "Text_Variable", the program do: 1 --> 4 or 1 --> 2 --> 3 --> 4
I could import from the script in "" without problems functions and variables which made the process 1 --> 4 work properly but I have a problem with the function "Menu_Options" :
I use "POST" method for getting the data from the page, so I need to pass the argument "request" to my function in "" but I call this function from the script, so I need to import that "request" in the module. I tried with these:

import newproject.views
import django
from django.http import request

Pregunta = 'question?'
Opciones = [op1, op2...]

opc = boletin.views.Menu_Opciones(request, Pregunta, Opciones)

def Menu_Opciones(request, Pregunta, Opciones):
    request.session['ops'] = Opciones
    request.session['preg'] = Pregunta
    opcion = request.session['op']
    return opcion

def Menu_Opc(request):
    Opciones = request.session['ops']
    Pregunta = request.session['preg']
    form = OpcionesForm(request.POST or None)
    form.Campo_Opciones.widget.choices = Opciones
    context = {
        'pregunta': Pregunta,
        'form': form,
    if form.is_valid():
        opcion = form.instance.ops.value() + 1
        request.session['op'] = opcion
    return render(request, "inicio.html", context)

but I had this error: "Menu_Opciones() missing 1 required positional argument: 'Opciones'"

Here is the traceback:


Request Method: POST
Request URL:

Django Version: 1.9.8
Python Version: 3.4.2
Installed Applications:
Installed Middleware:


File "C:\Users\ATI\Desktop\probardjango\lib\site-packages\django\core\handlers\" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "C:\Users\ATI\Desktop\probardjango\lib\site-packages\django\core\handlers\" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\ATI\Desktop\probardjango\src\boletin\" in inicio
  42.         salida = main(pregunta)

File "C:\Users\ATI\Proyecto\ESI\" in main
  52.             Respuesta = construir_respuesta(pregunta_lista, 'Profesores', CSin, TMaxCoin)

File "C:\Users\ATI\Proyecto\ESI\" in construir_respuesta
  127.             opc = boletin.views.Menu_Opciones(Pregunta, Opciones) <--(Request?)

Exception Type: TypeError at /
Exception Value: Menu_Opciones() missing 1 required positional argument: 'Opciones'

Am I doing something wrong this way or there are a better way to do this?
Please, consider I'm new in this language.
Thanks in advance.

What I have tried:

I tried to import the request object in the script in this way:

import django
from django.http import request

but it seems to be "ignored"
Updated 13-Aug-16 2:24am

1 solution

I fixed it! I realised that I forgot to pass the "request" parameter when I call my script main funcion. That's why my external script "didn't know" what "request" was.
Member 14430943 18-Sep-19 15:01pm
Hey can you explain your solution? i am stuck in same problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900