0

フォームを見ようとすると、空白のhtmlページが表示されます。

私が試したURLは次のとおりです:http://:8000 / catalog / enter_product /

http://screencast.com/t/16JpxtvMTd

モジュール名は存在しますが:

ここでわかるように、settings.pyは「SOWL」フォルダーにあり、CATALOGは同じレベルの別のフォルダーです http://screencast.com/t/bsHiglMl7

settings.pyには次のものがあります。あなたは「カタログ」がそれらの上にあるのを見ることができます。

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'CATALOG',
    'SOWLAPP',
    'registration',
)

SOWL / URls.pyには、次のコードが表示されます。メインURLで「カタログ」を呼び出すとき。CATALOG.urlsファイルを探します。

urlpatterns = patterns('',
     url    (r'^user/(\w+)/$', user_page),
    (r'^login/$', 'django.contrib.auth.views.login'),
    # (r'^catalog/$', home),
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        { 'document_root' : 'C:/SHIYAM/Personal/SuccessOwl/SOWL0.1/SOWL/SOWL/static'}),
    # (r'^admin/', include('django.contrib.admin.urls')),
    (r'^catalog/', include('CATALOG.urls')),
    (r'^accounts/', include('registration.urls')),
    (r'^$', main_page),
)


CATALOG.urls

from django.conf.urls.defaults import *
from CATALOG.views import *

urlpatterns = patterns('SOWL.catalog.views',
    (r'^$', 'index', { 'template_name':'catalog/index.html'}, 'catalog_home'),
    (r'^category/(?P<category_slug>[-\w]+)/$', 'show_category', {'template_name':'catalog/category.html'},'catalog_category'),
    (r'^product/(?P<product_slug>[-\w]+)/$', 'show_product', {'template_name':'catalog/product.html'},'catalog_product'),
    (r'^enter_product/$',enter_product),
)

CATALOG/models.pyにはこのクラスがあります

class Product(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField(max_length=255, unique=True, help_text='Unique value for product page URL, created from name.')
    brand = models.CharField(max_length=50)
    sku = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=9,decimal_places=2)
    old_price = models.DecimalField(max_digits=9,decimal_places=2, blank=True,default=0.00)
    image = models.CharField(max_length=50)
    is_active = models.BooleanField(default=True)
    is_bestseller = models.BooleanField(default=False)
    is_featured = models.BooleanField(default=False)
    quantity = models.IntegerField()
    description = models.TextField()
    meta_keywords = models.CharField(max_length=255, help_text='Comma-delimited set of SEO keywords for meta tag')
    meta_description = models.CharField(max_length=255, help_text='Content for description meta tag')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    categories = models.ManyToManyField(Category)
    user = models.ForeignKey(User)

    class Meta:
        db_table = 'products'
        ordering = ['-created_at']

    def __unicode__(self):
        return self.name

    @models.permalink
    def get_absolute_url(self):
        return ('catalog_product', (), { 'product_slug': self.slug })

    def sale_price(self):
        if self.old_price > self.price:
            return self.price
        else:
            return None

CATALOG/forms.pyには次のクラスがあります。

class Product_Form(forms.Form):
    name = forms.CharField(label='name', max_length=30)
    slug = forms.SlugField(label='Unique Name for the URL', max_length=30)
    brand = forms.CharField(label='Unique Name for the URL', max_length=30)
    price = forms.DecimalField(label='Price',max_digits=9,decimal_places=2)
    old_price = forms.DecimalField(max_digits=9,decimal_places=2,initial=0.00)
    quantity = forms.IntegerField()
    description = forms.CharField()
    meta_keywords = forms.CharField(max_length=255)
    meta_description = forms.CharField(max_length=255)
    categories = forms.CharField(max_length=255)
    user = forms.IntegerField()

    prepopulated_fields = {'slug' : ('name',)}

CATALOG / views.pyには次のものがあります:

# Create your views here.
from CATALOG.forms import *
from django.template import RequestContext
from django.shortcuts import render_to_response

def enter_product(request):
    if request.method == 'POST':
        form = Product_Form(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.clean_data['username'],
                password=form.clean_data['password1'],
                email=form.clean_data['email']
            )
            return HttpResponseRedirect('/')
    else:
        form = Product_Form()
    variables = RequestContext(request, {
            'form': form
        })

    return render_to_response('catalog/enter_product.html',variables)

SOWL \ templates \ catalog\enter_product.htmlには次のコードがあります

{% extends "base.html" %}
{% block title %}blah{% endblock %}
{% block head %}blah{% endblock %}
{% block content %}
<form method="post" action=".">
{{ form.as_p }}
<input type="submit" value="Enter" />
</form>
{% endblock %}

SOWL \ templates \ catalog\base.htmlには次のコードがあります。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Django Bookmarks |
{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="/site_media/style.css"
type="text/css" />
</head>
<body>
<div id="nav">
<a href="/">home</a> |
{% if user.is_authenticated %}
welcome {{ user.username }}
(<a href="/logout">logout</a>)
{% else %}
<a href="/login/">login</a>
{% endif %}
</div>
<h1>{% block head %}{% endblock %}</h1>
{% block content %}{% endblock %}
</body>
</html>

自分の意見がどのように作られているのかと関係があると感じています。ビューのproduct_formクラスがまったく使用されていないようです。

4

1 に答える 1

0

次のことを念頭に置いて

render_to_response(template[, dictionary][, context_instance][, mimetype])

あなたのCATALOG/views.pyファイルではcontext_instance、そのdictionary位置で渡しているので、enter_product関数で次の変更を加えてください。

variables = dict(
    form=form
)
于 2012-09-21T15:17:29.817 に答える