私は最近、Python/Djangoプロジェクトを開発しました。Python/Djangoプロジェクトは、Gitをバージョンコントロールとして使用していました。Django- NoReverseMatch
私はサーバーに行った変更をプッシュしたので、私が行った変更は、私が取り組んでいたバグを修正しましたが、バグはユーザーがプロジェクトの別の部分が何らかの形で壊れていました(「AddsOmits」というタイトルのページ)...しかし、私はその部分に何も変更を加えていないので、どのようにわからないのですか?
master
ブランチに変更をマージする際にいくつかのエラーが発生したため、以前のコミットをチェックアウトする必要があったため、私の修正が実際に破られた部分がプロジェクトの以前のバージョンに由来する可能性があります。したがって、これは以前のコミットに存在していたバグである可能性があります。
ライブサーバーのバージョンを、私が修正プログラムをアップロードする前の状態に戻しました。現在作業中の「日付」のバグは別として、動作状態です。
私のローカルマシンでは、ライブバージョン(すなわち、 '日付'のバグがまだ存在する)と同じmaster
とdateReceived
の2つのブランチがあります(つまり、しかし、ここで「AddsOmits」のページが壊れている私は、ブラウザに「AddsOmits」のページに私を取る必要があるリンクをクリックすると
(dateReceived
枝の上に、私が言うのページを提示しています:。
を引数を指定して「EXPORT_CSV」「(」「」)とキーワード引数 『{}』が見つかりませんため費用/ id/adds_omitsのNoReverseMatch
リバース:
エラーメッセージの「例外値」は以下のように与えられます。 1つのパターン(複数可)試してみました:[u'costing//エクスポート-CSV/$ '(P [0-9] +?)]
とページがあっError during template rendering
た、と言うこと:
テンプレート/Users/.../costing/templates/costing/adds_omits.html、行28のエラー 引数 '(' '、)'およびキーワード引数 '{}'を使用して 'export_csv'見つかりました。 1つのパターン(複数可)試してみました:[u'costing//エクスポート-CSV/$ '(P [0-9] +?)]
ライン、それは文句のテンプレートの28は次のとおりです。
<a class="button m-r-md" href="{% url 'costing:export_csv' budget.id %}">Export to Excel</a>
ブラウザが苦情を申し立てているエラーは、ビューcosting:export_csv
の呼び出しと関係があり、URLパターンが一致しない可能性があることを正しく理解しているようです。
import csv
from django.utils.encoding import smart_str
def export_csv(request, budget_id):
budget = Budget.objects.get(id=budget_id)
items = budget.budget_items.all()
field_names = ('Build type', 'Build type detail', 'Item type client', 'Room', 'Name', 'Detail', 'Quantity', 'Unit', 'Cpu', 'Materials cost', 'Skill days', 'Labour days', 'Other unit', 'Other rate', 'Line margin', 'Total inc profit', 'Notes')
fields = ([1, 'get_build_type_display'], 'build_type_detail', 'item_type_client', [1, 'get_room_name'], 'name', 'detail', 'quantity', 'unit', 'cpu', 'materials_cost', 'skill_days', 'labour_days', 'other_unit', 'other_rate', 'line_margin', 'total_inc_profit', 'notes')
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=Budget-'+budget.project.project_code+'.csv'
writer = csv.writer(response, csv.excel)
response.write(u'\ufeff'.encode('utf8')) # BOM (optional...Excel needs it to open UTF-8 file properly)
writer.writerow([
smart_str(u""+field_name) for field_name in field_names
])
for obj in items:
row = []
for field in fields:
if field[0] == 1:
if hasattr(obj,field[1]): row += [smart_str(u""+plain_char(unicode(getattr(obj,field[1])() or '')))] # For methods such as get_build_type_display()
elif hasattr(obj,field): row += [smart_str(u""+plain_char(unicode(getattr(obj,field) or '')))]
writer.writerow(row)
return response
URLパターン:私は右の私のエディタ(崇高)内のテンプレートにcosting:export_csv
をクリックし、「後藤の定義」を選択した場合
、I原価計算/ views.pyにview
定義に取られています原価計算/ビューで定義されたview
を呼び出すために使用されます。
url(r'^(?P<budget_id>[0-9]+)/export-csv/$', views.export_csv, name='export_csv'),
と私の知る限り、すべてが正しく(定義&呼び出し、など)と一致...私はここで間違って
は何をやっている:pyがありますか?ブラウザのエラーメッセージにある「例外値」は、私がどこかで引数を渡すべきか、別のものを渡すべきか/私が渡していないものを渡すべきであることを示しているようです。
この例外の理由は何ですか?どのように解決できますか?どんな助けでも大歓迎です。
編集
adds_omits
ためview
がで定義されます。
def adds_omits(request, project_id):
project = Project.objects.select_related('variations').prefetch_related('variations__addomit_set','variations__addomit_set__item').get(id=project_id)
budget = get_current_budget(project_id)
try: v = project.variations
except ObjectDoesNotExist: v = Variations.objects.create(project=project)
adds_omits = project.variations.addomit_set.select_related('item', 'item__project_room', 'item__project_room__room').all().order_by('item__build_type', 'item__build_type_detail', 'item__project_room', 'item__order', 'item__id') #Needs id to prevent other ordering within groups
budget_items = BudgetItem.objects.select_related('addomit', 'addomit__variations', 'addomit__variations__project', 'project_room', 'project_room__room').filter(addomit__variations=v).order_by('build_type', 'build_type_detail', 'project_room', 'order', 'id') #Needs id to prevent other ordering within groups
item_formset = BudgetItemFormsetLite(queryset=budget_items, form_kwargs={"ao":True,'project':project})
ao_formset = AddOmitFormset(instance=v, queryset=adds_omits)
formsets = zip(list(item_formset.forms), list(ao_formset.forms))
for i_form in item_formset:
for field in i_form.fields:
if not field == 'id':
i_form.fields[field].widget.attrs['readonly'] = True
i_form.fields[field].widget.attrs['disabled'] = True
#Used to create new add omits
print 'Item form ini'
item_form = BudgetItemForm(project=project, template=1)
var_type_form = AoVariationTypeForm()
context = {
'project': project,
'formsets': formsets,
'ao_formset': ao_formset,
'item_formset': item_formset,
'var_type_form': var_type_form,
'item_form': item_form,
'widths': budget_item_column_widths[4:], #First column is add/delete options to allow for forloop count offset
'options_width': "5em", #First column is add/delete options to allow for forloop count offset
'widths_ao': add_omit_column_widths,
'widths_item': budget_item_column_widths, #First column is add/delete options to allow for forloop count offset
'labour_rate': labour_day_rate,
'skill_rate': skill_day_rate,
}
return render(request, 'costing/adds_omits.html', context)
変更をマスターブランチにマージする際にどのようなエラーがありましたか?問題の根本はそこにあり、上記のコードとは何の関係もありません。 – Nevertheless
私はマージ後にエラーが発生した 'master'ブランチを破棄し、' master'ブランチをこのバグの作業を開始する直前にコミットに置き換えたので、 'master'ブランチは現在ライブ作業版。私のOPで説明した問題は、 'dateReceived'ブランチにしか存在しません。このブランチで修正したいので、' master'をサーバにプッシュする前にこのブランチを 'master'とマージできます。 – someone2088