0

I am trying to learn how to use cookiecutter and have created my own django based project that contains some static jinja2 templates referencing .js, .map files.

I have created and adapted this from a working local project that successfully displays a webapp when running python manage.py runserver.

However, when I try to run my cookie-project I get a jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got ':' for a third party js.min.js.map file as listed below:

It is as though cookiecutter is trying to parse the map file?? Shouldn't cookiecutter copy the static files across to the new project? How can I debug why this is happening?

error raised when I try to use my cookie cutter project

$ cookiecutter my-cookiecutter-project

description [desc]: desc
email [me@example.com]: 
full_name [Your Name]: me
license [MIT]: 
project_name [default_project]: myproj
python_version [3.8]: 
Traceback (most recent call last):
  File "/Users/simon/Library/Python/3.8/bin/cookiecutter", line 8, in <module>
    sys.exit(main())
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/cookiecutter/cli.py", line 140, in main
    cookiecutter(
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/cookiecutter/main.py", line 101, in cookiecutter
    result = generate_files(
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/cookiecutter/generate.py", line 352, in generate_files
    generate_file(
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/cookiecutter/generate.py", line 169, in generate_file
    tmpl = env.get_template(infile_fwd_slashes)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 997, in get_template
    return self._load_template(name, globals)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 958, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/jinja2/loaders.py", line 137, in load
    code = environment.compile(source, name, filename)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 757, in compile
    self.handle_exception(source=source_hint)
  File "/Users/simon/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "./{{ cookiecutter.project_name }}/local/api/static/assets/plugins/chartist-js/dist/chartist.min.js.map", line 1, in template
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got ':'
dcs3spp
  • 493
  • 1
  • 9
  • 23

1 Answers1

1

Solved it! The problem was that cookiecutter was trying to render the jinja2 templates during copy operation.

As stated here there is an option to copy and not render jinja2 templates.

So...I updated my cookiecutter.json to:

{
  "description": "desc",
  "email": "me@example.com",
  "full_name": "Your Name",
  "license": "MIT",
  "project_name": "default_project",
  "python_version": "3.8",
   "_copy_without_render": [
        "*.html",
        "*.js",
        "*.map",
        "*.css"
   ]
}

Now it is working!

dcs3spp
  • 493
  • 1
  • 9
  • 23