小编rv_*_*v_k的帖子

搜寻在Django的通配符

我们怎样才能在Django中进行通配符搜索.如果我从数据库中的列表中过滤用户名,如何使用这些确切的用户名或部分用户名显示过滤后的数据.

def filter(request):
    val3='' 
    if request.GET.has_key('choices'):
        val2=request.GET.get('choices')
    if request.GET.has_key('textField'):
        val3=request.GET.get('textField')
    if request.POST:
        val2=request.POST.get('choices')    
        val3=request.POST.get('textField')
    if val2=='Designation':                
        newData = EmployeeDetails.objects.filter(designation=val3) 
        flag=True 
    elif val2=='Name':
        newData = EmployeeDetails.objects.filter(userName=val3)
        flag=True 
    elif val2=='EmployeeID':
        newData = EmployeeDetails.objects.filter(employeeID=val3)  
        flag=True       
    elif val2=='Project':
        newData = EmployeeDetails.objects.filter(project=val3)   
        flag=True   
    elif val2=='DateOfJoin':
        newData = EmployeeDetails.objects.filter(dateOfJoin=val3) 
        flag=True       
    else:
        return HttpResponseRedirect('/employeeList/')
Run Code Online (Sandbox Code Playgroud)

这是我的过滤功能.现在用精确的单词过滤.我想显示userNames,即使它的一部分用于过滤.请帮我解决这个问题,因为我是Django的新手

django django-templates django-models django-queryset django-views

1
推荐指数
2
解决办法
6434
查看次数

'str'对象不支持项目分配 - django出错

我创建了一个Django应用程序.该应用程序具有用户注册页面.注册页面已实施,我正在尝试在注册后实施电子邮件确认.即在用户注册时发送电子邮件.在这样做时我遇到了这个错误,"'str'对象不支持项目分配".有人可以帮我解决这个问题.将粘贴我的代码.

def registrationForm(request):
    if request.method == "POST":  
        firstName = request.POST.get("firstName")
        lastName = request.POST.get("lastName")
        email = request.POST.get("email")
        password = request.POST.get("password")
        sex = request.POST.get("sex")
        birthday = request.POST.get("birthday")
        print request.POST.get("sex")
        UniversityDetails(firstName=firstName,lastName=lastName,email=email,password=password,sex=sex,birthday=birthday).save()

        msg = "Registration Successfull"
        msg['Subject'] = 'The contents of %s' 
        msg['From'] = me
        msg['To'] =you 
        s = smtplib.SMTP()
        s.sendmail(me, [you], msg.as_string())
        s.quit()

        return render_to_response('registrationForm.html')

    return render_to_response("registrationForm.html")
Run Code Online (Sandbox Code Playgroud)

HTML

<form name ="myform"  method="POST" id='FormID'>

<table>
<tr>
<td>First name</td>
<td>
<input type="text" name="firstName" value=""  maxlength="100" />
<b id="firstNameID" style="font-family:Times New Roman;color:#B4045F;font-size:14px;">
</td>
</tr>

<tr>
<td>Last …
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-models email-verification

1
推荐指数
1
解决办法
4552
查看次数

django中的语法错误

导致此urls.py语法错误的原因是什么?

它说

syntax error at Line 27[(r'^xd_receiver\.html$',.....] in ursl.py.
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚问题出在哪里.

  urlpatterns = patterns('',
        # Example:
        # (r'^universityDB/', include('universityDB.foo.urls')),

        # Uncomment the admin/doc line below to enable admin documentation:
        # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
        # Uncomment the next line to enable the admin:
        (r'^admin/', include(admin.site.urls)),
        (r'^registrationForm/$','universityDB.universityDetails.views.registrationForm'),
        (r'^userDetails/$','universityDB.universityDetails.views.userDetails'),
        (r'^login/$','universityDB.universityDetails.views.login'),
        (r'^userCreated/$','universityDB.universityDetails.views.userCreated'),
        (r'^forgotPassword/$','universityDB.universityDetails.views.forgotPassword'),
        (r'^passwordRecovery/$','universityDB.universityDetails.views.passwordRecovery'),     
        (r'^accounts/profile', 'universityDB.universityDetails.views.profile'),   
        (r'^xd_receiver\.html$', direct_to_template, {'template': 'xd_receiver.html'}, name='xd_receiver'),   
        (r'^login_facebook_connect/$', 'login_facebook_connect', name='facebook_connect_ajax'),

    )
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-models django-urls

1
推荐指数
1
解决办法
746
查看次数

包含的urlconf中没有任何模式+ django

我一直在尝试django教程并坚持这个错误.我在教程的第3页,一切都很顺利,直到我遇到这个错误Django教程.我正在按照教程中的确切步骤操作.这是我得到的错误

ImproperlyConfigured at /polls
The included urlconf <module 'polls.urls' from 'C:\\Python34\\mysite\\polls\\urls.py'> doesn't have any patterns in it
Run Code Online (Sandbox Code Playgroud)

我在这里粘贴我的代码.

ROOT_URLCONF = 'mysite.urls'` in settings.py, 
from django.conf.urls import patterns, url
from polls import views

urlpattern = patterns('',
    url(r'^$',views.index,name='index')
)`
Run Code Online (Sandbox Code Playgroud)

在MYSITE/POLLS/URLS.PY中

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
) 
Run Code Online (Sandbox Code Playgroud)

INSIDE MYSITE.URLS.PY

对不起,如果我错过了我必须提到的任何东西,以获得清晰的图片.任何帮助,将不胜感激.

python django url urlconf

1
推荐指数
1
解决办法
3468
查看次数

NameError - 未定义全局名称

我试图从html表单中读取一些数据并将其插入数据库.这样做我坚持这个错误"/ nameEmployee /的NameError:全局名称'get_post_param'未定义"; 我会在这里粘贴我的代码.有人可以帮我解决这个问题.
VIEWS.PY

def createEmployee(request):
    if request.method == "POST":
        userName = get_post_param(request,"userName")
        designation = get_post_param(request,"designation")
        employeeID = get_post_param(request,"employeeID")
        contactNumber = get_post_param(request,"contactNumber")
        project = get_post_param(request,"project")
        dateOfJoin = get_post_param(request,"dateOfJoin")
        EmployeeDetails(userName=userName,designation=designation,employeeID=employeeID,contactNumber=contactNumber,project=project,dateOfJoin=dateOfJoin).save()
        return render_to_response('createEmployee.html')
    else:
        return render_to_response('createEmployee.html')
Run Code Online (Sandbox Code Playgroud)

TEMPLATE.PY

<form action="http://127.0.0.1:8000/createEmployee/" method="POST"> 
Name: <input type="text" name="userName" /><br />
Designation: <input type="text" name="designation" /><br>
EmployeeID: <input type="text" name="employeeID" /><br>
Contact Number: <input type="text" name="contactNumber" /><br>
Project: <input type="text" name="project" /><br>
Date Of Join: <input type="text" name="dateOfJoin" /><br>
<input type="submit" value="Submit" /><br />
</form>
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-models django-views

-1
推荐指数
1
解决办法
8929
查看次数