Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:36:18+00:00 2026-06-05T01:36:18+00:00

I’m new at django and I’m having problems with a simple form POST.I have

  • 0

I’m new at django and I’m having problems with a simple form POST.I have a ModelForm in forms.py and when user enters information in html, views.py taks it and saves it. However, I keep getting an error saying it can’t find the view doesn’t exist in view.py. Please help me find the error. Thank you!

urls.py

urlpatterns = patterns('',
                       (r'^mypage/(?P<username>\w+)/$', 'recipeapp.views.my_view'),

forms.py

class NewRecipeForm(forms.ModelForm):

    user_info = forms.ForeignKey(User)
    title = forms.CharField(min_length=2,max_length=50,required=True,)
    post_date = forms.DateField(auto_now=True)
    ingredients = forms.TextField(widget=forms.Textarea(),)
    picture = forms.ImageField(upload_to='photos/%Y/%m/%d',)
    content = forms.TextField(widget=forms.Textarea(),)

views.py

@csrf_protect
from recipeapp.forms import NewRecipeForm

    def my_view(request,username):
        if request.method == 'POST':
            form = NewRecipeForm(request.POST)
            if form.is_valid():
                form.save()
        else:
            form = NewRecipeForm()

        return render_to_response('postlogin.html',{'username':username},{'form': form}, RequestContext(request))

postlogin.html

        <form action="" method="post" id="form">
            {% csrf_token %}

                <div id="dish-name">
                <label><p>Dish name</p></label>
                {{form.title}}
                </div>

                <div id="ingredients">
                <label><p>Ingredients</p></label>
                {{form.ingredients}}
                </div>

                <div id="content">
                <label><p>Content</p></label>
                {{form.content}}
                </div>

                {{form.picture}}
       </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:36:19+00:00Added an answer on June 5, 2026 at 1:36 am

    Is that really your whole views.py? You have at least three issues:

    Firstly, you haven’t imported csrf_protect – like any name, a decorator needs to be defined before you can use it.

    Secondly, you have to decorate an actual function, not a file. The decorator should go just before the function definition for my_view.

    Thirdly, your indentation is broken – the def should not be indented at all.

    Given all those, I expect that Python is failing to import your views because of syntax errors.

    Also note that you shouldn’t really use csrf_protect – you should enable CSRF protection in your middleware (it’s on by default) and only use the csrf_exempt decorator, and then only on very very rare occasions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.