Wednesday, October 8, 2014

Re: How do I create a simple user view web page to create/add mysql db entries?



On Tuesday, October 7, 2014 5:20:26 PM UTC-4, Bovine Devine wrote:
Thanks for the help Collin...I need to read through more of the documentation it seems! Going through the chapter am I correct in understanding that using ModelForm example you listed as a view does not need to be added to urls then? What is the user access page then? Sorry this is all really still new to me and I do not understand why they are running. I went back to review the forms documentation here: https://docs.djangoproject.com/en/1.7/topics/forms/ so is this two different ways to do the same thing?

There are many ways... There are two separate methods, in the documentation, which have some overlap.

Collin has been pointing you in the direction of function based views.  FBV are a good starting point, easier to follow the logic.

The modern method is Class Based Views.  CBV has a lot of utility with a tougher learning curve.  Much redundancy is managed in the base classes, which hides logic.

CBVs minimize coding.  The cost is the learning curve.

views.py:
from django.views.generic import ListView, TemplateView, DetailView, CreateView, DeleteView, UpdateView
from oneidentry.models import Hardwareid

class MyView(CreateView):
    model = Hardwareid
    template_name = 'base_site.html'
    fields = ['hardwareid_text']

urls.py:
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from oneidentry.views import MyView

urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name="index.html"), name='index'),
url(r'^create/$', views.add_view, name='add_view'),
    )

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/2f987232-4025-4eba-a1da-0c2c8596fe28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment