我試圖在URL中傳遞slu but,但我無法這樣做。 slu is如果有一個文本的形式: - text: - 這是Stackoverflow slu:: - 這是 - stackoverflow 但我無法實現這一點。 我的模型: -如何在Django中傳遞slu 012作爲url
from __future__ import unicode_literals
from django.db import models
class EmailTemplates(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
subject = models.CharField(db_column="subject",max_length=255)
slug = models.CharField(db_column="slug",unique=True, max_length=255)
content = models.TextField(db_column="content", help_text="")
createdAt = models.DateTimeField(db_column='createdAt',auto_now=True, help_text="")
modifiedAt = models.DateTimeField(db_column='modifiedAt',auto_now=True, help_text="")
updatedBy = models.IntegerField(db_column='updatedBy', help_text="")
class Meta:
managed = False
db_table = 'email_templates'
我的網址我試圖爲: -
url(r'^email/edit/(?P<email_template_id>[\w-]+)/$', email_managment.email_send, name='email-edit')
我的看法是這樣的: -
@login_required
@csrf_exempt
def email_send(request,email_template_id):
try:
form = emailTemplates(request.POST or None)
edit_email_end = 'add'
email_template_obj = {}
if request.method == 'POST':
if form.is_valid():
subject = request.POST.get('subject')
lowercase = subject.lower()
slug = lowercase.replace(" ","-")
print slug
content = request.POST.get('content')
if email_template_id is None or email_template_id == '':
add_email_template_entry = EmailTemplates(subject=subject, content=content,slug=slug)
add_email_template_entry.save(using="cms")
messages.success(request, 'Successfully added to the email template page')
elif email_template_id:
email_template_obj = EmailTemplates.objects.using("cms").get(id=email_template_id)
email_template_obj.subject = subject
email_template_obj.content = content
email_template_obj.slug = slug
email_template_obj.save(using="cms")
messages.success(request, 'Successfully update to the email templates')
return redirect('cms:email-list')
if email_template_id is not None:
edit_email_end = 'edit'
email_template_obj = EmailTemplates.objects.using("cms").get(id=email_template_id)
return render(request, 'templates/email_managment/add_email.html',{
'edit_email_end': edit_email_end,'email_template_obj':email_template_obj})
except Exception as e:
print e
raise Http404
這是正在添加的錯誤是
invalid literal for int() with base 10: 'hello-took-of-fools'
請忽略格拉瑪如果有任何的話,就會出現錯誤 在此先感謝
你是什麼意思,你無法通過slu??你怎麼試過的?你做了什麼事?你得到了什麼錯誤? –
錯誤:對於int()以10爲基數的無效文字:'你好 - 傻瓜' –
你需要顯示完整的回溯,所以我們知道錯誤來自哪裏。你也應該展示你的模型。 –