好像我被卡住了。我需要你的帮助来解决这个错误。 我认为URL上的正则表达式是烂的。任何帮助将不胜感激。
这是错误:
File" /Users/cohen/Documents/project/sanctions/batches/urls.py", 第2行,在 来自。导入视图文件" /Users/cohen/Documents/project/sanctions/batches/views.py" ;,第23行 def detail_businessname(request): ^ SyntaxError:语法无效
这些是我的模特:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class Batches(models.Model):
BatchNumber = models.IntegerField(null=True)
FileName= models.CharField(max_length=250)
UploadedDate= models.DateField(max_length=250)
UploadedBy = models.CharField(max_length=250)
NumberOfRows= models.IntegerField(null=True)
Hits= models.IntegerField(null=True)
Status= models.CharField(max_length=250)
class Meta:
verbose_name_plural = "Batches"
def __str__(self):
return self.FileName + '- ' + str(self.Hits) + '- ' + str(self.NumberOfRows) + '- ' + self.Status
class BusinessName(models.Model):
AccountingCode = models.CharField(max_length=50)
RefID = models.CharField(max_length=50, default="")
FullName = models.CharField(max_length=250)
Aliases = models.CharField(max_length=250)
Address = models.CharField(max_length=500)
City= models.CharField(max_length=50)
ZipCode= models.IntegerField(null=True)
State = models.CharField(max_length=250)
Country= models.CharField(max_length=250)
TypeOfSanction= models.CharField(max_length=250)
Monitoring= models.CharField(max_length=50)
BatchNumber= models.IntegerField(null=True) # tr pus automat
FileName= models.CharField(max_length=250) # tr pus automat1
UploadDate = models.DateField(max_length=250) # tr pus automat
UploadBy= models.CharField(max_length=250) # tr pus automat
Decision= models.CharField(max_length=250) # tr pus Ulterior
Status= models.CharField(max_length=250) # tr pus automat
EngineDecision= models.CharField(max_length=250) # tr pus automat
WhoAdjudicated= models.CharField(max_length=250)
DateOfAdjudication= models.CharField(max_length=250)
SdnType = models.CharField(max_length=250) #Entity or Individual
class Meta:
verbose_name_plural = "Business Names"
def __str__(self):
return self.FullName + '-' + self.Address + '-' + self.City + '-' + '-' + self.State + '-' + self.Country
class Individuals(models.Model):
AccountingCode = models.CharField(max_length=50)
RefID = models.IntegerField(null=True)
FullName = models.CharField(max_length=250)
FirstName= models.CharField(max_length=250)
Lastname= models.CharField(max_length=250)
DayOfBirth = models.IntegerField(null=True)
MonthOfBirth = models.IntegerField(null=True)
YearOfBirth= models.IntegerField(null=True)
FullDOB = models.DateField(max_length=250)
Aliases = models.CharField(max_length=250)
Address = models.CharField(max_length=500)
City= models.CharField(max_length=50)
ZipCode= models.IntegerField(null=True)
State = models.CharField(max_length=250)
Country= models.CharField(max_length=250)
TypeOfSanction= models.CharField(max_length=250)
Monitoring= models.CharField(max_length=50)
BatchNumber= models.IntegerField(null=True) # tr pus automat
FileName= models.CharField(max_length=250) # tr pus automat
UploadDate= models.DateField(max_length=250) # tr pus automat
UploadBy= models.CharField(max_length=250) # tr pus automat
Decision= models.CharField(max_length=250) # tr pus Ulterior
Status= models.CharField(max_length=250) # tr pus automat
EngineDecision= models.CharField(max_length=250) # tr pus automat
WhoAdjudicated= models.CharField(max_length=250)
DateOfAdjudication= models.CharField(max_length=250)
More= models.CharField(max_length=250)
SdnType = models.CharField(max_length=250) #Entity or Individual
class Meta:
verbose_name_plural = "Individuals"
def __str__(self):
return self.FullName + '-' + self.Address + '-' + self.City + '-' + '-' + self.State + '-' + self.Country
这是我的观点:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from .models import BusinessName
from .models import Individuals
from .models import Batches
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
all_Batches = Batches.objects.all()
html = ''
for batch in all_Batches:
url = '/batches/' + str(batch.id) + '/'
html += '<a href="#"' + url + '">' + str(Batches.BatchNumber)+ '</a><br>'
return HttpResponse(html)
def detail(request, BatchNumber):
return HttpResponse("<h2>Details for Batches ID:" + str(BatchNumber + "</h2")
def detail_businessname(request):
all_BusinessNames = BusinessName.objects.all()
html = ''
for BN in all_BusinessNames:
url = '/businessname/' + str(BusinessName.id) + '/'
html += '<a href="#"' + url + '">' + BusinessName.FullName + '</a><br>'
return HttpResponse(html)
def detail_individuals(request):
return HttpResponse("<h2>Details for Individual Names ID:" + str(Individuals.id) + "</h2")
这些是网址:
from django.conf.urls import url
from . import views
urlpatterns = [
# /batches/
url(r'^$', views.index, name='index'),
# /batches/2
url(r'^(?P<batches_id>[0-9]+)/$',views.detail, name="detail"),
# businessname/1
url(r'^(?P<businessname_id>[0-9]+)/$',views.detail_businessname, name="detail_businessname"),
# individuals/1
url(r'^(?P<individuals_id>[0-9]+)/$', views.detail_individuals, name="detail_individuals"),
非常感谢, 科恩
答案 0 :(得分:2)
你错过了封闭的braket
return HttpResponse("<h2>Details for Batches ID:" + str(BatchNumber + "</h2"))