Can't save input to database

55 views
Skip to first unread message

Ronis

unread,
Dec 30, 2014, 2:42:48 PM12/30/14
to django...@googlegroups.com
Hi guys, I can't save the input from a custom form to database. I don't know what I am missing. 

Because it's using a downloaded template from the web, I'm not using the django forms. Instead, I'm trying to simply save the input from the html form to the database. Im using the standard database when you create a django project. When I checked the admin the inputs are not saved. 

Here is my code: 






I'm a newbie programmer btw, this may be simple solution but I've spent some time and couldn't figure it out =/ 

Thomas Lockhart

unread,
Dec 30, 2014, 3:02:12 PM12/30/14
to django...@googlegroups.com
On 12/30/14 11:42 AM, Ronis wrote:
Hi guys, I can't save the input from a custom form to database. I don't know what I am missing.
I'm not sure either. But the html form you posted looks a *lot* like any template you might find in a django deployment. If it were me I'd look harder at just tying that in to the "usual places" and be done with it. That will give you form validation etc nearly for free and save the next person who is looking at your code from having to figure out what you did. Patterns and idioms save a lot of thinking best used elsewhere...

hth

- Tom


Because it's using a downloaded template from the web, I'm not using the django forms. Instead, I'm trying to simply save the input from the html form to the database. Im using the standard database when you create a django project. When I checked the admin the inputs are not saved. 

Here is my code: 






I'm a newbie programmer btw, this may be simple solution but I've spent some time and couldn't figure it out =/ 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca13d351-0075-4000-902d-3f8755cb775e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Khemlani

unread,
Dec 30, 2014, 5:43:41 PM12/30/14
to django...@googlegroups.com
the code sample links are broken :(

Ronis

unread,
Jan 2, 2015, 9:04:22 AM1/2/15
to django...@googlegroups.com
Sorry I didn't the snippets are only available for 24 hours or little more. They should extend that. 

So finally I got it right! Uffa! 


So basically I did one little change to the html code actually, and it worked. 

Here was the code:

<div id="h">
      <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
              <h1>Vem aí a 99 <bold>FITNESS</bold></h1>
              <h3>Em breve o maior aplicativo de fitness do Brasil</h3>
              <div class="col-md-6 col-md-offset-3">
                <form role="form" action="{% url 'home' %}" method="post" enctype="plain">{% csrf_token %} 
                  <input type="email" name="email" id="u_email" class="subscribe-input" placeholder="Coloque seu e-mail..." required>
                  <button class='btn btn-conf btn-go' type="submit">Quero ser avisado e virar vip!</button>
                </form>

I changed the action="/signup/" to action="{% url 'home'%}" and it start saving the input to database. 

Now my question is... because it wasn't a django code it wasn't working or because I was passing the wrong html page? Because actually signup is the page right after the form action, after the user submits the input. Do I always have to specify the actions form forms in django code like that? 

I tried using "/home/" instead and gave me an error. 


Anyway I'm happy finally this simple thing is done! Thanks for the help btw

Collin Anderson

unread,
Jan 4, 2015, 2:23:34 PM1/4/15
to django...@googlegroups.com
Hi,

You shouldn't have to use the {% url %} syntax. What does it end up generating if you view the source of the page? Is it /home/?

What was the error?

Collin
Reply all
Reply to author
Forward
0 new messages