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 7508989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:46:58+00:00 2026-05-29T22:46:58+00:00

I’m currently trying to learn Django from the book and I read most of

  • 0

I’m currently trying to learn Django from the book and I read most of it and am now trying to write a webapp of my own. I just really can’t figure out how they all interact and how they aren’t fitting together.


My urls.py file reads like this…

from django.conf.urls.defaults import patterns, include, url
from users.views import homepageview, submitted, referral_create

urlpatterns = patterns('',
(r'^$', homepageview),
(r'^submitted/$', referral_create),

the views.py file looks like this…

  # Create your views here.
from django.shortcuts import render_to_response
from django import forms
from datreferral.users.forms import ReferralCode

def homepageview(request):
    now = 'your damn referral code'
    return render_to_response('datreferraltemplate.html', {'now': now})

def referral_create(request):
    if request.method == 'POST':
        form = ReferralCode(request.POST)
        if form.is_valid():
            new_code = form.save()
            return HttpResponseRedirect(reverse(contact_details, args=(new_contact.pk,)))
    else:
        form = ReferralCode()

The form.py file looks like

from django import forms

class ReferralCode(forms.Form):
    referralcode = forms.CharField()

and the template looks like this…

{% extends "base.html" %}

{% block title %}
Enter your referral codes!
{% endblock %}

{% block content %}
<h1>Enter your code</h1>

    {% if errors %}
        <ul>
            {% for error in errors %}
            <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}

    <form action="" method="POST">
        <p>Subject: <input type="text" name="subject" value="{{ referralcode }}"></p>
        <input type="submit" value="Submit">
    </form>
{% endblock %}

Hopefully that’s enough info.

I am looking for two things. First off, when I try to view the page after submitting the form i get no where because I assume that the “if request.method == ‘POST’:” is not triggering. Obviously its something pretty obvious but I’m in one of those modes where I can find the bug for the life of me.

The second question I have is basically is plea for help. somehow after reading through those chapters multiple times I can’t seem to nail down how all of the pieces interact with each other. I know that the template and the urls.py and the views.py interact and I get (I think) but I can’t really grasp how the database and forms interact with each other and with the views/templates. like say I just wanted to a simple form where whatever the use inputted is written into the database… How would you do that? I’m using postgres if that matters.

Note: the form and the in the template is a modified version of code i found on here and tried to manipulate to meet my needs but failed so don’t be overly thrown off if that doesn’t make sense I wasn’t able to mess with that part that much yet because of these problems.

As I’m new to web development I really appreciate any one willing to help me or point me in the right direction.

  • 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-05-29T22:46:58+00:00Added an answer on May 29, 2026 at 10:46 pm
    1. You don’t return anything in you else clause. A views must always return a response, which can be pretty much anything, but in most cases you will return a instance of a (sub)-class of HttpResponse (I really like the render shortcut). It is a good idea to have a default return at the bottom of you view, add some early returns for “special” responses and otherwise let the execution reach the default return – this way you never have the case where you return nothing.

    2. You have to use a Model to save data (have you work through the tutorial?). Usually the excution model is the following:

      1. you app gets a request and the urls.py is searched for a view that should be called
      2. the request is passed through the middleware
      3. you view is called and “does” something. I.e. it fetches data from the database (again using a model) or stores something in the db (or saves a uploaded file, sends a mail, etc. – aview can really do anything)
      4. you view returns “something”
      5. the returned “something” is passed through the middleware and will eventually be tranformed in a stream of data that is passed to the browser

    Thats it. This is a bit simplified but it pretty much covers all important parts.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.