GithubHelp home page GithubHelp logo

marcofucci / cookiecutter-simple-django Goto Github PK

View Code? Open in Web Editor NEW
101.0 5.0 53.0 147 KB

A cookiecutter template for creating reusable Django projects quickly.

License: BSD 3-Clause "New" or "Revised" License

Python 52.57% Makefile 21.19% CSS 0.15% JavaScript 0.17% HTML 6.68% Batchfile 19.25%

cookiecutter-simple-django's Introduction

cookiecutter-simple-django

A cookiecutter template for Django.

Description

Lighter version of the Daniel Greenfeld's cookiecutter-django.

It uses the latest stable versions and it only defines a skeleton which can be extended as needed.

Usage

Let's pretend you want to create a Django project called "redditclone". Rather than using startproject and then editing the results to include your name, email, and various configuration issues that always get forgotten until the worst possible moment, get cookiecutter to do all the work.

First, get cookiecutter. Trust me, it's awesome:

Set up your virtualenv:

$ cd <your-envs-folder>
$ virtualenv  --no-site-packages redditclone
$ cd redditclone
$ source bin/activate
$ pip install cookiecutter

Now run it against this repo:

$ cd <your-workspace>
$ cookiecutter  https://github.com/marcofucci/cookiecutter-simple-django.git

You'll be prompted for some questions, answer them, then it will create a Django project for you.

Warning: After this point, change 'Marco Fucci', etc to your own information.

It prompts you for questions. Answer them:

Cloning into 'cookiecutter-django'...
remote: Counting objects: 443, done.
remote: Compressing objects: 100% (242/242), done.
remote: Total 443 (delta 196), reused 419 (delta 176)
Receiving objects: 100% (443/443), 119.91 KiB | 0 bytes/s, done.
Resolving deltas: 100% (196/196), done.
project_name (default is "project_name")? redditclone
repo_name (default is "repo_name")? redditclone
author_name (default is "Your Name")? Marco Fucci
email (default is "Your email")? <your-email>
description (default is "A short description of the project.")? A reddit clone
year (default is "Current year")? 2013
with_documentation (default is "yes")? yes

If you are using cookiecutter < 0.7 and you answered no to with_documentation, you might want to delete the docs folder. From version 0.7+, that folder is automatically deleted for you.

Create the database redditclone and then set up your project:

$ cd redditclone/
$ ls
$ pip install -r requirements/local.txt
$ python ./manage.py syncdb
$ python ./manage.py migrate
$ python ./manage.py runserver

and load localhost:8000/admin

Create a GitHub repo and push it there:

$ git init
$ git add .
$ git commit -m "first awesome commit!"
$ git remote add origin [email protected]:marcofucci/redditclone.git
$ git push -u origin master

Note: The requirements files don't define any package versions because it makes more sense for you to use the latest ones when you set up your project. After that point though, you really want to take note of the specific versions installed so that they are not going to get updated without you knowing it.

In order to do this, just activate your virtual environment, pip freeze it and update your requirements files:

$ activate <your-envs-folder>/redditclone/bin/activate
$ pip freeze
$ # now open requirements/* and note down the versions used.

Structure

The structure used should look quite familiar:

Requirements

The requirements folder contains a requirements file for each environment.

If you need to add a dependency please choose the right file.

Settings

The settings folder contains a settings file for each environment and the local settings should be gitignored.

If you take a look at base.py, you'll see that it includes the optional module local.py in the same folder. There you can override the local values and gitignore will exclude it from your commits.

The testing.py module is loaded automatically after base.py and local.py every time you run python ./manage.py test.

Apps

The apps folder should contain all your local django apps, this is to keep the structure of the project clean.

When it's time to python ./manage.py startapp <name>, just move the generated module to apps. If you want to know why this works, just take a look at the line:

sys.path.insert(0, root('apps'))

in settings/base.py.

Done!

Now, it's time to write the code!!!

Not Exactly What You Want?

This is what I want. It might not be what you want. Don't worry, you have options:

Fork This

If you have differences in your preferred setup, I encourage you to fork this to create your own version. Once you have your fork working, let me know and I'll add it to a 'Similar Cookiecutter Templates' list here. It's up to you whether or not to rename your fork.

If you do rename your fork, I encourage you to submit it to the following places:

  • cookiecutter so it gets listed in the README as a template.
  • The cookiecutter grid on Django Packages.

Or Submit a Pull Request

I also accept pull requests on this, if they're small, atomic, and if they make my own project development experience better.

cookiecutter-simple-django's People

Contributors

a7p avatar angvp avatar chrisfreeman avatar dupuy avatar gbourdin avatar jefftriplett avatar kevgathuku avatar marcofucci avatar mgaitan avatar mrmikee avatar pydanny 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  avatar  avatar

cookiecutter-simple-django's Issues

mod_wsgi (pid=19121): Target WSGI script 'index.wsgi' cannot be loaded as Python module.

Hi all, having this issue with following index.wsgi setup:

import os
import sys
 
sys.path.append('/home/dev/project/backlab/')
sys.path.append('/home/dev/venv/lib/python3.5/site-packages/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'backlab.settings'
import django
django.setup()
 
from django.core.handlers import wsgi
application = wsgi.WSGIHandler()

Test project structure:

|____portal
| |____migrations
| |____models.py
|____requirements.txt
|____requirements
| |____testing.txt
| |____jenkins.txt
| |____production.txt
| |____base.txt
| |____local.txt
|____docs
|____.gitignore
|____backlab
| |____settings
| | |____local.py
| | |______init__.py
| | |____testing.py
| | |____base.py
| | |____production.py
| |____templates
| |____urls.py
| |____assets
| |____apps
| | |______init__.py
| |____views.py
| |____wsgi.py
|____LICENSE.rst
|____manage.py

.DS_Store?

You seem to have a .DS_Store file in one of the directories. Is this on purpose for some reason? I don't own a Mac, so I have no idea what they are.

testing issue

The hack to put the application within the project, doesn't play well with testing. Do you have any clue to improve this situation? I have to the put the full module name in INSTALLED_APPS instead.

=============================================== test session starts ===============================================
platform linux -- Python 3.6.0, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
Django settings: chain_reaction.settings (from ini file)
rootdir: /home/yoan/work/hearc/webappII/tsuro/tsuro, inifile: tox.ini
plugins: django-3.1.2
collected 0 items / 1 errors 

===================================================== ERRORS ======================================================
_______________________________ ERROR collecting chain_reaction/apps/games/tests.py _______________________________
chain_reaction/apps/games/tests.py:3: in <module>
    from .models import Game
chain_reaction/apps/games/models.py:9: in <module>
    class Game(TimeStampedModel):
.tox/py36-pypi/lib/python3.6/site-packages/django/db/models/base.py:113: in __new__
    "INSTALLED_APPS." % (module, name)
E   RuntimeError: Model class chain_reaction.apps.games.models.Game doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

clean way to write apps not working in django 1.7

RuntimeError: Conflicting 'tag' models in application 'inventory': <class 'inventory.models.Tag'> and <class 'groot.apps.inventory.models.Tag'>.

feels similar to this: https://code.djangoproject.com/ticket/22280#comment:13

here is my sys.path:

['/home/redskins80/project-groot/groot/groot/apps',
 '/home/redskins80/project-groot/groot',
 '/home/redskins80/project-groot/env-groot/lib/python2.7',
 '/home/redskins80/project-groot/env-groot/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/redskins80/project-groot/env-groot/lib/python2.7/lib-tk',
 '/home/redskins80/project-groot/env-groot/lib/python2.7/lib-old',
 '/home/redskins80/project-groot/env-groot/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/redskins80/project-groot/env-groot/local/lib/python2.7/site-packages',
 '/home/redskins80/project-groot/groot',
 '/home/redskins80/project-groot/groot']

is there a way to still structure our apps this way in 1.7?

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.