django-baker icon indicating copy to clipboard operation
django-baker copied to clipboard

Django 2.0?

Open danieljfarrell opened this issue 7 years ago • 2 comments

Hello,

Does this project support Django 2.0 running on Python 3.6?

I get the following error using bake.

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django_baker/management/commands/bake.py", line 23, in handle
    baker.bake(ingredients)
  File "/usr/local/lib/python3.6/site-packages/django_baker/bakery.py", line 28, in bake
    self.create_init_files(app, model_names.keys(), models)
  File "/usr/local/lib/python3.6/site-packages/django_baker/bakery.py", line 70, in create_init_files
    "model_names_dict": model_names_dict
  File "/usr/local/lib/python3.6/site-packages/django_baker/bakery.py", line 120, in create_file_from_template
    new_file.write(get_template(template_path).render(Context(context_variables)))
  File "/usr/local/lib/python3.6/site-packages/django/template/backends/django.py", line 59, in render
    context = make_context(context, request, autoescape=self.backend.engine.autoescape)
  File "/usr/local/lib/python3.6/site-packages/django/template/context.py", line 274, in make_context
    raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)
TypeError: context must be a dict rather than Context.

danieljfarrell avatar Dec 31 '17 20:12 danieljfarrell

Not sure about your specific issue, but FYI, in general this is not compatible with Python 3, but it's an easy manual fix. See #18 that I just opened.

matthewslaney avatar Jan 17 '18 21:01 matthewslaney

Line 120 of bakery.py needs to be changed from: render(Context(context_variables))) to: render(context_variables))

Django 1.10 deprecated "Context" being accepted in render.

https://docs.djangoproject.com/en/dev/internals/deprecation/

Django template objects returned by get_template() and select_template() won’t accept a Context in their render() method anymore.

However, be aware that there are several other conflicts to moving to Django 2.0. Specifically how it handles URLs has some conflicts as well.

alkelaun avatar Mar 25 '18 02:03 alkelaun