Giter Site home page Giter Site logo

tangowithcode / tango_with_django_2_code Goto Github PK

View Code? Open in Web Editor NEW
117.0 3.0 173.0 1.18 MB

Django 2 and Python 3: Tango With Django 2 Code Repository (for book 2020-01a)

Home Page: https://www.tangowithdjango.com

License: MIT License

Python 100.00%
python3 django2 tutorial

tango_with_django_2_code's People

Contributors

asimeonovuog avatar maxwelld90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tango_with_django_2_code's Issues

Test Fail for Chapter 8.

Hello,

I have finished Chapter 8 and when doing the tests, I get 1 failure - I've been looking over the code for a couple days and can't seem to work out what I have to change. If you could help that would be great - think i'm just not understanding the error. I have included my github link if you need to look at that.

https://github.com/emilymurphy2110/TangoProject

Screenshot 2020-02-14 at 10 22 13

About the 4th Test

Sorry for doing the actions so late. I figured out where is the problem for can't pass the test even the page shows the correct content. The HTML code for showing the picture has to be exactly same as

<img src="{% static 'images/rango.jpg' %}" alt="Picture of Rango" />

No SPACE or LINE BREAK is allowed ๐Ÿ˜ต

I personally think that maybe a little bit too harsh for people who need to pass the test to get the grade like university students. I wish it can be changed to a more friendly test : ) ๐Ÿ˜„

Chapter 5 Tests

The tests for Chapter 5 are producing the error message on line 178 of the tests_chapter5.py file. The error message reads:
"We couldn't find the correct output in the Page view within the admin interface for page listings. Did you complete the exercises, adding extra columns to the admin view for this model? Are the columns in the correct order?"

I can see that the pertinent test checks whether expected_str is in response_body. When I print response_body, the string is identical to expected_str except for the start of the string, which begins instead of , but everything else is the same.

I.e. response_body reads:

image

instead of:

image

The code in my admin.py file for the project reads as follows:

"from django.contrib import admin
from rango.models import Category, Page

class PageAdmin (admin.ModelAdmin):
list_display = ('title', 'category', 'url')

Register your models here.

admin.site.register(Category)
admin.site.register(Page,PageAdmin)"

which matches the code suggested in the Excercise Hints part of the book on Page 89. The code also produces the correct Pages view on the /admin/ site:

image

The above is a screenshot of the /admin/ page from my project which exactly matches the screenshot on page 88 of the book.

I am running a later version of Django than suggested in the book (4.1), which perhaps explains this error.

Can you please confirm whether there is something wrong with my implementation or whether the error is produced due to external reasons (e.g. using a later version of Django)? Thanks in advance for your help!

URL inconsistency in tests_chapter6

In Creating a Population Script in chapter 5 of the book, the sample code gives the URL for Django Rocks as http://www.djangorocks.com/, with a trailing forward slash.
2020-01-19 19_49_55-tangowithdjango2 pdf -  Tango With Django 2  - SumatraPDF

In the test_index_pages method on line 108 of tests_chapter6.py, the index view responses are checked using regex, including a check for Django Rocks as http://www.djangorocks.com, without the trailing forward slash.
2020-01-19 19_44_17-tests_chapter6 py - Visual Studio Code
This of course results in the test failing.

Unit test for chapter 3 require specific project name

One of the unit tests from chapter 3 requires the directory name to be exactly "tango_with_django_project". This is a bit inconsistent with the instructions from the book (page 27).

This command will invoke the django-admin.py script, which will set up a new Django project called tango_with_django_project for you. Naming conventions dictate that we would typically append _project to the end of our Django project directories so we know exactly what they contain โ€“ but naming this is really entirely up to you.

Unit test case:

 def test_project_created(self):
        """
        Tests whether the tango_with_django_project configuration directory is present and correct.
        """
        directory_exists = os.path.isdir(os.path.join(self.project_base_dir, 'tango_with_django_project'))
        urls_module_exists = os.path.isfile(os.path.join(self.project_base_dir, 'tango_with_django_project', 'urls.py'))
        
        self.assertTrue(directory_exists, f"{FAILURE_HEADER}Your tango_with_django_project configuration directory doesn't seem to exist. Did you use the correct name?{FAILURE_FOOTER}")
        self.assertTrue(urls_module_exists, f"{FAILURE_HEADER}Your project's urls.py module does not exist. Did you use the startproject command?{FAILURE_FOOTER}")

My suggestion is to remove the directory assertion and leave only the "urls_module_exists" -- adapting it to ignore the project name.

Chapter 3 Tests Fail : syntax error on line 26 : FAILURE HEADER

Completed exercises until end of Chapter 3.
Upon executing the tests for chapter 3 get following error:

File "/home/aspma/python/django/tango_with_django_project/rango/tests_chapter3.py", line 26
FAILURE_HEADER = f"{os.linesep}{os.linesep}{os.linesep}================{os.linesep}TwD TEST FAILURE =({os.linesep}================{os.linesep}"

----------------------------------------------- Console Output --------------------------------------------
SyntaxError: invalid syntax

(rangoenv) aspma@aspma-VirtualBox:~/python/django/tango_with_django_project$ python manage.py test rango.tests_chapter3
Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 56, in handle
failures = test_runner.run_tests(test_labels)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/test/runner.py", line 603, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/test/runner.py", line 485, in build_suite
tests = self.test_loader.loadTestsFromName(label)
File "/usr/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName
module = import(module_name)
File "/home/aspma/python/django/tango_with_django_project/rango/tests_chapter3.py", line 26
FAILURE_HEADER = f"{os.linesep}{os.linesep}{os.linesep}================{os.linesep}TwD TEST FAILURE =({os.linesep}================{os.linesep}"
^
SyntaxError: invalid syntax

----------------------------------------------- Console Output --------------------------------------------

Chapter 11 - python_2_unicode_compatible

Hi -

A definite newbie to Django (and even Python) and I'm getting the below error when attempting Chapter 11:

"File "/Users/kent/.virtualenvs/rangoprojenv/lib/python3.8/site-packages/registration/models.py", line 21, in
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/Users/kent/.virtualenvs/rangoprojenv/lib/python3.8/site-packages/django/utils/encoding.py)"

I've googled the above and the solutions I find discuss altering external libraries which I'm definitely not comfortable with doing at the moment (especially as one of the lines could not even be found - otherwise might have attempted it).

Is it something I missed in the book, a bug on my part, or any chance a compatibility error as most posts I've seen have hinted at? Not much coding in Chapter 11 and can't see where I might have gone wrong (though I've coded enough to know it could definitely be me!).

New to Github too but will post code if the need arises.

Thanks,

Kent

Tests at the end of chapter 4 require hard coded path to media

The required str in test_about_contains_rango:

required_str = f"<img src=\"{settings.MEDIA_URL}cat.jpg\" alt=\"Picture of a Cat\" />"

fails if about.html contains context variable like:

<img src="{{ MEDIA_URL }}cat.jpg" alt="Picture of a Cat.">

only was to pass the test seems to be to hard code the path to media:
<img src="/media/cat.jpg" alt="Picture of a Cat" />

Not sure if this is intended or if the context variable for media should also pass the test.

The overriden clean() method in PageForm class doesn't produce the desired effect

Hello,
I understand that by overriding the clean() method in PageForm class the URL box on the ../add_page/ webpage should also accept URLs that don't begin with 'http://'.
But it appears that the method is called only after the URL box is validated for incorrect format of URL, therefore it's never called until you type the URL correctly formatted in the first place.
I tried cloning your chapter7 branch and it produced the same result as my project.

Is there a mistake or do I understand the purpose of the method in a wrong way?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.