正如你可以看到的那樣,我有一個奇怪的捕獲NoReverseMatch,同時呈現: accounts_profile_view'與參數'('',)'和關鍵字參數'{}'未找到。在Django使用時shell_plus,導入用戶配置文件,然後從django.urlcore.resolvers進口反函數在呈現時捕獲NoReverseMatch:未找到參數'('',)'和關鍵字參數'{}'的'accounts_profile_view'的相反
最奇怪的是我這樣做:
reverse('accounts_profile_views', args=[username])
和它的作品就好了!
我爲你們創造了一堆要點,幫助我回顧他們,在這裏他們是。
這是模型 https://gist.github.com/140127f6303660baf8d9
這是我的觀點文件 https://gist.github.com/1a3b9651eef3fb9d22db
這是我的模型的URL https://gist.github.com/66fe6b1f068739f940db
,這是整個項目的URL https://gist.github.com/edea781b1efca341230b
和當然錯誤 https://gist.github.com/8b84bd0394d4b047dce8
感謝您的幫助社區!
====== UPDATE ======
我發現一些東西,那裏有一些奇怪的事情發生在CONTACT_US視圖和模板,當我去接觸我們頁面request.user頭上的.username顯示一個空的var。
我的繼承人CONTACT_US網址這是該項目的主要觀點部分:
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
urlpatterns = patterns('apps.maincoke.views',
url(r'^(?i)$', 'home', name='home'),
url(r'^(?i)faqs/$', direct_to_template, {'template': 'maincoke/faqs.html'}, name="main_faqs"),
url(r'^(?i)contact-us/$','contact_us', name='contact_us'),
)
這是CONTACT_US觀點:
@login_required
@render_to("maincoke/contact_us.html")
def contact_us(request):
mail_status = None
if request.method == 'POST':
contact_us_form = ContactUsForm(request, request.POST)
if contact_us_form.is_valid():
mail_status = contact_us_form.send_as_mail()
if mail_status:
contact_us_form = ContactUsForm(request)
else:
contact_us_form = ContactUsForm(request)
return { 'contact_us_form' : contact_us_form, 'mail_status' : mail_status }
,這是形式,即時通訊使用Django-UNI形式
class ContactUsForm(forms.Form):
name = forms.CharField(label='Nombre', max_length=120, required=True)
email = forms.CharField(max_length=200, required=True)
message = forms.CharField(label='Mensaje', widget=forms.Textarea(attrs={'cols':'40'}),
required=True)
MAX_MESSAGE_LENGTH = 2000
# uniForm Helper
helper = FormHelper()
helper.form_id = "contact_us_form"
layout = Layout(
Fieldset('',
'name', 'email', 'message'
)
)
helper.add_layout(layout)
# Submit button(s)
submit = Submit('submit','Enviar')
helper.add_input(submit)
class Meta:
fields = ['name', 'email', 'message']
def __init__(self, request, *args, **kw):
super(ContactUsForm, self).__init__(*args, **kw)
self.request = request
def clean_message(self):
message_data = self.cleaned_data['message']
if len(message_data) > self.MAX_MESSAGE_LENGTH:
raise forms.ValidationError("Mensaje demasiado largo")
def send_as_mail(self):
data = self.cleaned_data
send_status=True
mail_content_html = render_to_string('mails/contactmail.html', {'data':data})
mail_content_text = strip_tags(mail_content_html)
mail = EmailMultiAlternatives("Mensaje enviado de %s" % data['name'],
mail_content_text,
settings.DEFAULT_FROM_EMAIL,
settings.CONTACT_MAIL_RECIPIENT
)
mail.attach_alternative(mail_content_html, "text/html")
try:
mail.send(fail_silently=False)
except:
send_status=False
return send_status
模板的信息根本沒有得到渲染!