通过URL传递字符串的上下文

2024-10-03 21:27:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着把一个molfile作为一个字符串传递给我的模板,这个模板是由一个SMILES字符串生成的,这样我就可以显示一个化学结构。你知道吗

class CompoundView(DetailView):
    template_name = 'CompoundDisplay.html'
    model = Compound

    def get_context_data(self, **kwargs):
        context = super(CompoundView, self).get_context_data(**kwargs)
        context_object_name = self.get_context_object_name(self.object)
        comp_pk = self.kwargs['pk']
        if context_object_name:
            context[context_object_name] = self.object
        comp_id = Compound.objects.get(pk=comp_pk)
        cursor = Smile.objects.get(compound_fk=comp_id.compound_ID)
        smile = cursor.smiles
        m = Chem.MolFromSmiles(smile)
        mol = Chem.MolToMolBlock(m)
        correct_mol = mol.replace('\n', '\\n')
        context['calc_factors'] = cursor
        context['mols'] = correct_mol
        context.update(kwargs)
        return context

一切正常,除了mol字符串,它被传递到页面,最后在url中出现这个,这显然不起作用。在CBV里有没有办法把它作为POST加载?还是我在别的地方出了问题?你知道吗

[15/Jan/2015 11:20:27] "GET /compounds/compound/298/RDKit%20%20%20%20%20%20%20%20%20%20%2044%2045%20%200%20%200%20%200%20%200%20%200%20%200%20%200%20%200999%20V2000%20%20%20%200.0000%20%20%20%200.0000%20%20%20%200.0000%20O%20%20%200%20%200%20%200%20%200%20%200%20%....2043%20%201%20%200%2043%2044%20%202%20%200%2043%20%202%20%201%20%200%2039%2035%20%201%20%200M%20%20END HTTP/1.1" 404 18005


Tags: 字符串nameself模板getobjectcontextcursor