0

I am building a web application using django. I need to take a string input from the user and process it using a method I have written myself. How to achieve this in Django? Here are the things I need to do

  1. Get User Input userinput = (string) On start page
  2. Put this string as an argument in my method MyMethod(userinput) and Run it in the backend
  3. Display what MyMethod() returns on another page.
2
  • What have you tried so far? This is not code-writing service, so please show your effort for people to be willing to help you. Start from reading Django tutorial, in particular section about writing simple forms. Commented Dec 29, 2015 at 23:26
  • I am sorry for I cant really share the code due.Till now I have seen the tutorials, I know how to create forms and store whatever is inputted into the db that django creates. I don't need a code from this service, I just need some indiactions. Thanks. Commented Dec 29, 2015 at 23:40

2 Answers 2

4

I suggest that you start from django tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial01/

Basically, what you are going to need is form with one text field, HTML template that will render the form, view that will render HTML template with instance of a form when GET request arrives and call your MyMethod with value from form when POST request arrives and URL rule to call your view function on some URL.

Without additional data or any attempt to solve it and concrete problem you encounter - I can hardly offer more help.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @del-boy . This is exactly what i was looking for. A hint as to how to get the input to the view file. I called the POST method and sent the command to a particular URL that I defined which in turn sent the stuff to my VIEW function for processing it, and a TEMPLATE displayed what I needed.
1

You need to create a model with fields which you want to update by user input, then create a form based on this model. Then import this in a view and render it in a template

simple example:
forms.py:

class InputForm(forms.ModelForm):

    class Meta:
        model = YourModel
        fields = ['fields_from_YourModel']

views.py:

from .forms import InputForm

def user_input(request):
    input = CustomUser.objects.get(pk=request.user.pk)
    if request.POST:
        form = ProfileForm(request.POST, instance=input)
        if form.is_valid:
            form.save()
    else:
        form = ProfileForm()
    return render(request, 'input.html', {'form':form})

Other steps more easier for beginner, you'll find examples in docs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.