Giter Club home page Giter Club logo

django-crash-starter's Introduction

django-crash-starter

Build Status

Powered by Cookiecutter, django-crash-starter is the project template for the Django Crash Course tutorial book by Daniel and Audrey Feldroy.

Django Crash Course: Covers Django 3.0 and Python 3.8

Features

  • For Django 3+
  • Works with Python 3.8+
  • Renders Django projects with 100% starting test coverage
  • Twitter Bootstrap v4
  • 12-Factor based settings via django-environ
  • Secure by default. We believe in SSL/TLS.
  • Optimized development and production settings
  • Registration via django-allauth
  • Comes with custom user model ready to go
  • Media storage using whitenoise
  • Run tests with unittest or pytest
  • PostgreSQL / SQLite3
  • Default integration with pre-commit for identifying simple issues before submission to code review

Constraints

  • Very small scope. New feature pull requests will generally be rejected.
  • Only maintained 3rd party libraries are used.
  • Environment variables for configuration

django-crash-starter's People

Contributors

ashwoods avatar audreyfeldroy avatar bogdal avatar browniebroke avatar burhan avatar chrisfranklin avatar crdoconnor avatar danihodovic avatar ddiazpinto avatar demestav avatar deoktr avatar dependabot-preview[bot] avatar eraldo avatar foarsitter avatar hackebrot avatar jayfk avatar kappataumu avatar kevgathuku avatar luzfcb avatar noisy avatar pydanny avatar pyup-bot avatar sfdye avatar shireenrao avatar tanoabeleyra avatar theskumar avatar toffer avatar trungdong avatar webyneter avatar yunti 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

Watchers

 avatar  avatar  avatar  avatar

django-crash-starter's Issues

Missing some imports and requirements

What happened?

When I execute python manage.py runserver I got the following traceback:

  File "/home/edvm/Code/edvm/python/cookiecutter/frula/config/settings/base.py", line 48, in <module>
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
NameError: name 'os' is not defined
(django3) 

Also BASE_DIR is missing (same file). After defining (locally) this variables, i get: ModuleNotFoundError: No module named 'debug_toolbar'

I installed debug_toolbar with: pip install django-debug-toolbar, then django_extensions is misisng. I pip install django_extensions and finally get it working.

What should've happened instead?

It should execute runserver without errors.

pd: I didn't send a PR as this issues are really small, but if you want and consider its ok, i can send a pr :)

Steps to reproduce

1- Create a new virtualenv, activate it.

2- Install cookiecutter

3- Clone this repo, create a project with: cookiecutter django-crash-starter, set sqlite as DB

4- cd project_dir and: pip install -r requirements.txt, then execute: python manage.py runserver.

Switch from ROOT_DIR to BASE_DIR

Description

Convert to the standard Django name as generated by startproject.

Rationale

Matches the Django nomenclature in startproject.

Auto-generate a default project_slug from project_name

Description

In other projects, we auto-generate a default project_slug from project_name. Let's do this here.

Rationale

To help newbies reduce the risk of errors from un-importable project slugs that they accidentally use.

Use case(s) / visualization(s)

A newbie accidentally sets project_slug to Every Cheese which is neither importable nor Pythonic (should be lowercase with underscores).

Coverage.py seems to missing something

I am on windows 10
The environment is miniconda as in the django-crash-course book.

After running the coverage run -m pytest

Test session starts (platform: win32, Python 3.8.2, pytest 5.3.5, pytest-sugar 0.9.2)
django: settings: config.settings.test (from option)
rootdir: C:\Users\Rahul\AppData\Roaming\plrplus\fastest\django-tests\everycheese, inifile: pytest.ini
plugins: django-test-plus-1.4.0, django-3.9.0, sugar-0.9.2
collecting ...
 everycheese/users/tests/test_forms.py ✓                                                                  11% █▎        
 everycheese/users/tests/test_models.py ✓                                                                 22% ██▎       
 everycheese/users/tests/test_urls.py ✓                                                                   33% ███▍       
 everycheese/users/tests/test_urls.py ✓✓                                                                  44% ████▌      
 everycheese/users/tests/test_urls.py ✓✓✓                                                                 56% █████▋    
 everycheese/users/tests/test_views.py ✓                                                                  67% ██████▋    
 everycheese/users/tests/test_views.py ✓✓                                                                 78% ███████▊   
 everycheese/users/tests/test_views.py ✓✓✓                                                                89% ████████▉  
 everycheese/users/tests/test_views.py ✓✓✓✓                                                              100% ██████████

Results (1.74s):
       9 passed

after running coverage report

No data to report.

That is inconsistent with what is in the book.

I smelled something fishy. I then opened .coveragerc

[run]
include = everycheese/*
omit = *migrations*, *tests*
plugins =
    django_coverage_plugin

That seems ok.

for testing, I just deleted the file.

running above codes after deleting .coveragerc file gave.

-------------------------------------------------------------------------------------------
config\__init__.py                                                          0      0   100%
config\settings\__init__.py                                                 0      0   100%
config\settings\base.py                                                    58      1    98%
config\settings\test.py                                                     8      0   100%
config\urls.py                                                             12      4    67%
everycheese\__init__.py                                                     2      0   100%
everycheese\conftest.py                                                    13      0   100%
everycheese\contrib\__init__.py                                             0      0   100%
everycheese\contrib\sites\__init__.py                                       0      0   100%
everycheese\contrib\sites\migrations\0001_initial.py                        6      0   100%
everycheese\contrib\sites\migrations\0002_alter_domain_unique.py            5      0   100%
everycheese\contrib\sites\migrations\0003_set_site_domain_and_name.py      11      4    64%
everycheese\contrib\sites\migrations\__init__.py                            0      0   100%
everycheese\users\__init__.py                                               0      0   100%
everycheese\users\admin.py                                                 12      0   100%
everycheese\users\apps.py                                                  10      0   100%
everycheese\users\forms.py                                                 18      0   100%
everycheese\users\migrations\0001_initial.py                                8      0   100%
everycheese\users\migrations\0002_user_bio.py                               4      0   100%
everycheese\users\migrations\__init__.py                                    0      0   100%
everycheese\users\models.py                                                 9      0   100%
everycheese\users\tests\__init__.py                                         0      0   100%
everycheese\users\tests\factories.py                                       14      0   100%
everycheese\users\tests\test_forms.py                                      15      0   100%
everycheese\users\tests\test_models.py                                      5      0   100%
everycheese\users\tests\test_urls.py                                       13      0   100%
everycheese\users\tests\test_views.py                                      40      0   100%
everycheese\users\urls.py                                                   4      0   100%
everycheese\users\views.py                                                 23      0   100%
-------------------------------------------------------------------------------------------
TOTAL                                                                     290      9    97%

Not what exactly in the book but acceptable compared to no data to report

Am I missing something, or this is due to buggy windows as always?

Test coverage at 98%

What happened?

UserUpdateView.form_valid() has two uncovered lines.

What should've happened instead?

These should be tested accurately

Steps to reproduce

  1. Generate project using defaults
  2. coverage run -m pytest
  3. coverage report
  4. coverage html

Check htmlcov/index.html

Working CI

Description

Setup preferably with GitHub actions to work on Linux, Mac, and Windows. But we can get by on just Linux.

Rationale

With Cookiecutters It's easy to break the build and not know about it. The answer is CI. It would be great if this could be done via GitHub actions.

Use case(s) / visualization(s)

Add a badge so we know for certain it's working at all times.

RuntimeError: Model class shop.models.Category doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

What happened?

Am having the following this error.
Am trying to build an online shop using the cookiecutter.

python manage.py runserver
Watching for file changes with StatReloader
INFO 2020-08-23 11:55:13,654 autoreload 13959 139651660433216 Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
all_issues = self._run_checks(
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/management/base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 407, in check
for pattern in self.url_patterns:
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/utils/functional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/utils/functional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/reus/Documents/WORK/elimubora/config/urls.py", line 28, in
path('cart/', include('elimubora.cart.urls',namespace='cart')),
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/reus/Documents/WORK/elimubora/elimubora/cart/urls.py", line 2, in
from . import views
File "/home/reus/Documents/WORK/elimubora/elimubora/cart/views.py", line 4, in
from elimubora.cart.cart import Cart
File "/home/reus/Documents/WORK/elimubora/elimubora/cart/cart.py", line 3, in
from shop.models import Book
File "/home/reus/Documents/WORK/elimubora/elimubora/shop/models.py", line 4, in
class Category(models.Model):
File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/db/models/base.py", line 112, in new
raise RuntimeError(
RuntimeError: Model class shop.models.Category doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

My apps look like this:
DJANGO_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
# "django.contrib.humanize", # Handy template tags
"django.contrib.admin",
"django.forms",
]

THIRD_PARTY_APPS = [
"crispy_forms",
"allauth",
"allauth.account",
"allauth.socialaccount",
]

LOCAL_APPS = [
"elimubora.users.apps.UsersConfig",
"elimubora.shop.apps.ShopConfig",
"elimubora.cart.apps.CartConfig",
"elimubora.orders.apps.OrdersConfig",
# Your stuff: custom apps go here
]

What should've happened instead?

Steps to reproduce

django.db.utils.OperationalError: fe_sendauth: no password supplied

What happened before?

Installed the dependencies as described in 18.6

pip install -r requirements/local.txt

then I ran migrate

What happens now?

now the error occurs
psycopg2.OperationalError: fe_sendauth: no password supplied

Last stable commit / Since when?

Steps to reproduce

python manage.py check doesn't pass

What happened?

I hacked the django-crash-starter cookiecutter for deployment to Heroku (I removed anymail, caches and logging). The github repo is here: And I got it up and running(). I ran heroku run python manage.py check --deploy -a <app-name> and got this:

?: (security.W022) You have not set the SECURE_REFERRER_POLICY setting. Without this, your site will not send a Referrer-Policy header. You should consider enabling this header to protect user privacy.

What should've happened instead?

It should have passed the checks

Steps to reproduce

run python manage.py check --deploy

pylint_celery missing dependency

What happened?

I got an error message on pylint:

Suspicious state from syntax checker python-pylint: Flycheck checker python-pylint returned 1, but its output contained no errors: Traceback (most recent call last):
  File "/Users/soloidx/.venvs/everycheese/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/Users/soloidx/.venvs/everycheese/lib/python3.8/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/Users/soloidx/.venvs/everycheese/lib/python3.8/site-packages/pylint/lint/run.py", line 303, in __init__
    linter.load_plugin_modules(plugins)
  File "/Users/soloidx/.venvs/everycheese/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 498, in load_plugin_modules
    module = modutils.load_module_from_name(modname)
  File "/Users/soloidx/.venvs/everycheese/lib/python3.8/site-packages/astroid/modutils.py", line 203, in load_module_from_name
    return load_module_from_modpath(dotted_name.split("."), path, use_sys)
  File "/Users/soloidx/.venvs/everycheese/lib/python3.8/site-packages/astroid/modutils.py", line 244, in load_module_from_modpath
    mp_file, mp_filename, mp_desc = imp.find_module(part, path)
  File "/Users/soloidx/.pyenv/versions/3.8.1/lib/python3.8/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'pylint_celery'

I assume that it is because in .pylintrc is configured to use the pylint_celery plugin but is not listen inside the requirements/local

What should've happened instead?

Should pass smoothly

Steps to reproduce

cookiecutter gh:feldroy/django-crash-starter

[creating a venv and enabling it]

pip install pylint
pylint

Generate a Markdown README rather than RST

Description

In the programming world, Markdown is becoming much more standard than RST.

Rationale

Markdown is more user-friendly and familiar to devs coming from non-Python backgrounds.

Improve settings/production.py

Description

Not very friendly when trying to deploy

Use case(s) / visualization(s)

These fields should have sane defaults or useful instructions:

  • SECRET_KEY
  • DATABASES
  • DJANGO_ADMIN_URL
  • ANYMAIL
  • COMPRESS_ENABLED should be switched to False as most users won't set up S3

Generate a better starting README

Description

The starting README should have more than just a TODO.

Rationale

Leaving TODOs in committed code is a deprecated practice. Issues are the standard way of filing TODOs.

Use case(s) / visualization(s)

By leaving the TODO in, we risk causing lots of Django projects to be created out in the wild with TODOs in their READMEs.

GitLab -> GitHub

Section 19.4 header reads ..GitLab.. when it clearly should be GitHub (or whatever preferred case).

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Trying to understand 35 wiring in the list view url

Description

35 Wiring in the List View Url
Where in the everycheese/cheeses/urls.py does it state that the views.CheeseListView.as_view() will be wired to cheese_list.html?

Rationale

Just curiosity

Use case(s) / visualization(s)

For instance, I have changed cheese_list.html file name to cheese_array.html and path(..., name=array) and it won't work. I would like to know

manage.py migrate import issue (EveryCheese)

What happened?

P. 98 of TwoScoops Django 3/Python 3.8 book
When running python manage.py migrate, encountered the following error (traceback):
Traceback (most recent call last): File "manage.py", line 34, in <module> execute_from_command_line(sys.argv) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute django.setup() File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/apps/config.py", line 90, in create module = import_module(entry) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'debug_toolbar'

What should've happened instead?

Should have gone off without a hitch.

Steps to reproduce

Follow all steps in Chapter 18 up to this point.

SOLUTION (HACKY):

run:
conda install django-debug-toolbar
installing the above with pip appears not to work.

Results in different error:
Traceback (most recent call last): File "manage.py", line 34, in <module> execute_from_command_line(sys.argv) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute django.setup() File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/site-packages/django/apps/config.py", line 90, in create module = import_module(entry) File "/Users/mgbvox/opt/anaconda3/envs/django/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'django_extensions'

condo installing django-extensions then allowed migrate to run.

Not sure what the underlying issue is here. But I do know the instructions in the book don't apply.

It seems a typo in file {{cookiecutter.project_slug}}/requirements/local.txt

albert@chelsea ~/.cookiecutters/django-crash-starter/{{cookiecutter.project_slug}}/requirements (master)

$ git diff local.txt 
diff --git a/{{cookiecutter.project_slug}}/requirements/local.txt b/{{cookiecutter.project_slug}}/requirements/local.txt
index e29a544e..74174c78 100644
--- a/{{cookiecutter.project_slug}}/requirements/local.txt
+++ b/{{cookiecutter.project_slug}}/requirements/local.txt
@@ -2,7 +2,7 @@
 
 Werkzeug==1.0.1 # https://github.com/pallets/werkzeug
 ipdb==0.13.2  # https://github.com/gotcha/ipdb
-{%- if cookiecutter.windows == 'n' -%}
+{%- if cookiecutter.windows == 'n' %}
 psycopg2-binary==2.8.5  # https://github.com/psycopg/psycopg2
 {%- endif %}

Is it possible to create everycheese project code in the current directory?

Description

When running cookiecutter gh:feldroy/django-crash-starter, a directory everycheese/ is created inside of the current working directory, containing all the code for the EveryCheese project.
Is it possible to create all the code in the current working directory?

Rationale

I'm using PyCharm with pipenv and it already creates a project directory with the virtual environment so I do not need an extra subdirectory inside of the working directory.
Screen Shot 2021-04-13 at 02 09 03

Use case(s) / visualization(s)

I'd like to do something similar to
django-admin startproject project_name .

Changing default language of 3rd party django apps

Description

How do I change default language of 3rd party django apps?
I've installed django-countries as instructed and it shows the country list in Korean.
I don't remember setting language in particular and yet, for some reason, it shows in such manner.
Same for the allauth apps (some of the headers are in Korean as well such as 'Log out').

Rationale

Migrate from the legacy dependabot configuration to the new dependabot config format

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.