twoscoops / django-twoscoops-project Goto Github PK
View Code? Open in Web Editor NEWThe sample project layout from the book, "Two Scoops of Django 1.5 and 1.6"
Home Page: http://twoscoopspress.org
License: MIT License
The sample project layout from the book, "Two Scoops of Django 1.5 and 1.6"
Home Page: http://twoscoopspress.org
License: MIT License
These are the (i believe) relevant lines from my bash history. Running Ubuntu 12.04, Python 2.7.3
# create virtualenv
mkvirtualenv twoscoops
deactivate
# command from the book needs django to begin with
sudo pip install django
# command from the book
django-admin.py startproject --template=https://github.com/twoscoops/django-twoscoops-project/zipball/master --extension=py,rst,html icrating
cd icrating/
cd icrating/
python manage.py runserver
cd ../requirements/
# install requirements
workon twoscoops
pip install -r local.txt
# run
python manage.py runserver
Running it yields me the following result
(twoscoops)andre@ubuntu:~/repos/icrating/icrating$ python manage.py runserver
/home/andre/.virtualenvs/twoscoops/local/lib/python2.7/site-packages/django/conf/__init__.py:219: DeprecationWarning: You have no filters defined on the 'mail_admins' logging handler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logged
DeprecationWarning)
/home/andre/.virtualenvs/twoscoops/local/lib/python2.7/site-packages/django/conf/__init__.py:219: DeprecationWarning: You have no filters defined on the 'mail_admins' logging handler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logged
DeprecationWarning)
Validating models...
0 errors found
January 20, 2013 - 23:33:02
Django version 1.5c1, using settings 'icrating.settings.local'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x92cb62c>>
Traceback (most recent call last):
File "/home/andre/.virtualenvs/twoscoops/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run
handler = self.get_handler(*args, **options)
File "/home/andre/.virtualenvs/twoscoops/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 24, in get_handler
handler = super(Command, self).get_handler(*args, **options)
File "/home/andre/.virtualenvs/twoscoops/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 40, in get_handler
return get_internal_wsgi_application()
File "/home/andre/.virtualenvs/twoscoops/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 65, in get_internal_wsgi_application
% (app_path, attr, module_name, e))
django.core.exceptions.ImproperlyConfigured: WSGI application 'wsgi.application' could not be loaded; can't find 'application' in module 'wsgi': 'module' object has no attribute 'application'
Every PaaS has it's quirks. Therefore, we should have for users the following:
Example files for a mythical TwoScoops PaaS:
requirements/twoscoops.txt
project_name/project_name/settings/twoscoops.py
Hi,
I have begun reading your book and enjoy it a lot. Thanks for the great content.
I use different devices with different screen sizes to read my ebooks and I find that epub format generally performs well where the content flows fluidly to fit the different screen sizes. I also tend to use very large fonts (16+). The rigid formatting and fixed font size in PDF is hurting me enjoying the great content of your book.
I tried converting the pdf to epub using calibre - but the output wasn't up to the mark with most of the formatting chewed up.
Can you consider offering an epub version as well please. It would greatly enhance my reading experience with this great book.
I'd like to see the information in your blog post (about form instance attributes) in Ch. 10 of 2 Scoops of Django.
I almost immediately needed to use this in an ecommerce project, and I re-read Ch. 10 of your book a couple times before I found my answer in the blog post.
when i run python manage.py runserver 0.0.0.0:8000
Traceback (most recent call last):
File "manage.py", line 9, in
execute_from_command_line(sys.argv)
File "/home/administrator/projects/rapidpro/env/local/lib/python2.7/site-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/home/administrator/projects/rapidpro/env/local/lib/python2.7/site-packages/django/core/management/init.py", line 345, in execute
settings.INSTALLED_APPS
File "/home/administrator/projects/rapidpro/env/local/lib/python2.7/site-packages/django/conf/init.py", line 46, in getattr
self._setup(name)
File "/home/administrator/projects/rapidpro/env/local/lib/python2.7/site-packages/django/conf/init.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/administrator/projects/rapidpro/env/local/lib/python2.7/site-packages/django/conf/init.py", line 98, in init
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'temba.settings' (Is it on sys.path? Is there an import error in the settings file?): Could not import settings 'temba.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings
Our current method:
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
# TODO - gmail should not be the default. What's a better option?
EMAIL_HOST = environ.get('EMAIL_HOST', 'smtp.gmail.com')
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
# TODO - should we provide list of possible email providers like sendgrid and mailgun?
EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', '')
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
# TODO - should we provide list of possible email providers like sendgrid and mailgun?
EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', '')
Are Sendgrid, Mailgun, or other email providers interested in getting involved?
according to the discover runner site, isn't discover runner part of 1.6 now and not required in the sample project?
hello pydanny,
very nice your template project, i'm going to use it in all my future projects!
but i don't understand, how do you activate your virtualenv from the apache configuration file?
i used to run activate.py from my wsgi.py file, but i see you don't.
i suppose you use a more elegant approach, but what is your method? i can't find it anywhere...
thanks!
UPDATE: I did find what was whooshing over my head. The Django root project dir is not the first icecream folder, it's the second one.. so everything makes sense now. I didn't want to erase all of this typed because maybe it serves to specify this somewhere (or maybe it's written somewhere but I didn't read :) )
Ok, I hope I can make myself clear, here I go :D
If I create a new project using django-twoscoops-project template I get this:
(mk)marco@dexter:~VIRTUAL_ENV/test/icecream|⇒ tree
.
├── CONTRIBUTORS.txt
├── docs
│ ├── conf.py
│ ├── deploy.rst
│ ├── index.rst
│ ├── __init__.py
│ ├── install.rst
│ ├── make.bat
│ └── Makefile
├── icecream
│ ├── icecream
│ │ ├── __init__.py
│ │ ├── settings
│ │ │ ├── base.py
│ │ │ ├── __init__.py
│ │ │ ├── local.py
│ │ │ ├── production.py
│ │ │ └── test.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── manage.py
│ ├── static
│ │ ├── css
│ │ │ ├── bootstrap.min.css
│ │ │ ├── bootstrap-responsive.min.css
│ │ │ └── project.css
│ │ ├── img
│ │ │ ├── glyphicons-halflings.png
│ │ │ └── glyphicons-halflings-white.png
│ │ └── js
│ │ ├── bootstrap.min.js
│ │ └── project.js
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ └── base.html
├── LICENSE.txt
├── README.rst
├── requirements
│ ├── base.txt
│ ├── local.txt
│ ├── production.txt
│ └── test.txt
└── requirements.txt
10 directories, 34 files
Here, I'm at the root of my icecream
project. In the Django Twoscoops book (great book btw, I bought it :)! ), I always see references to settings file like this: icecream.settings.local
but that actually is not how this folder structure is made. For this to work, I would have to export my DJANGO_SETTINGS_MODULE
to icecream.icecream.settings.local
.
The settings folder is inside two 'myproject' folders. This also breaks stuff like the ROOT_URLCONF
directive in settings.
Because:
ROOT_URLCONF = '%s.urls' % SITE_NAME
says that the urls.py file is located at icecream.urls
but that's not actually true, it's located at icecream.icecream.urls
.
Is something just whooshing over my head or is this folder structure wrong? Thanks!
Does it make sense to document this:
https://docs.djangoproject.com/en/dev/topics/testing/overview/#speeding-up-the-tests
in the book or this django template? I've found it very useful.
cheers
The readme doesn't mention https://github.com/twoscoops/two-scoops-of-django-1.8 and probably should.
I hope I'm categorizing this post as a question, but not sure.
I'm just curious about why there are no Urls.py at the project level, and only in the app level.
The Django tutorial has you including the polls sample app's urls.py file into the " root URLconf " urls.py, located one directory up:
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
But in the 2scoops django project template, there is only the single urls.py in the sample app.
Is there an article, or section of Django documentation that explains how Django decides which directory to search for, when looking for urls.py files to find the final urlpatterns it needs?
After a lot of consideration, I've decided that it's a good idea to bump this to Django 1.6. My reason is that while my cookiecutter-django project is pretty good, lots of people prefer the straight-forward approach of this project as well.
Therefore, I'll begin accepting Django 1.6 and Python 2.7/3.3 cross-language support pull requests.
Was merged into master - shouldn't it have gone into the develop branch instead?
Hi,
I'm following the book, I'm reading Chapter 7 and I would like to have model.py and data to query the data and see how some of the methods explained in the book works. Does anyone know where to download the DB with data and model.py?
now if launch the command RUN SERVER, i get this error
DatabaseError at / admin /
no such table: django_session
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.5.1
Exception Type: DatabaseError
Exception Value: no such table: django_session
Two Declaration of ALLOWED_HOSTS in production.py
That is correct?
When I put the Procfile as
web: gunicorn mysite.wsgi:application
and then I run it using foreman start. But it's failing to start with this error
ImportError: No module named mysite.wsgi
23:55:37 web.1 | 2013-03-30 23:55:37 [6119] [INFO] Worker exiting (pid: 6119)
23:55:37 web.1 | 2013-03-30 23:55:37 [6116] [INFO] Shutting down: Master
23:55:37 web.1 | 2013-03-30 23:55:37 [6116] [INFO] Reason: Worker failed to boot.
23:55:37 web.1 | exited with code 3
23:55:37 system | sending SIGTERM to all processes
I didn't bother making a pull request for this because it's simple and I'm not sure if there's a reason it's not done already.
By default, local.txt is a superset of test.txt already, and I'm not sure of the use case where a test runner environment would need to be different from a local development environment (although I guess it's quite possible such a case exists?) - but I can definitely see the use case where the local development environment should be set up to run all the same tests that the test runner is going to run.
I tend to make the first line of my local.txt "-r test.txt" for the above reason, and that seems to me to be a better default?
The # comments have too many # and are generating warnings in flakes
e.g.
########## IN-MEMORY TEST DATABASE
No need for them, can have something like:
################################################################################
# IN-MEMORY TEST DATABASE
################################################################################
which doesn't generate any warnings
Wouldn't it be better to have local.txt look like this
-r test.txt
django-debug-toolbar==1.0.1
Sphinx==1.2.1
That way local and test are kept in sync on the versions of:
coverage==3.6
django-discover-runner==0.4
Here is the result of my pip freeze after using the icecream_project template:
(klovenv)vagrant@precise64:/vagrant/ksink/icecream_project$ pip freeze
Django==1.6.2
Jinja2==2.7.2
MarkupSafe==0.23
Pygments==1.6
South==0.8.2
Sphinx==1.2.1
argparse==1.2.1
bpython==0.12
coverage==3.6
django-braces==1.2.2
django-debug-toolbar==1.0.1
django-discover-runner==0.4
django-model-utils==1.5.0
docutils==0.11
logutils==0.3.3
six==1.6.1
sqlparse==0.1.11
wsgiref==0.1.2
However, this raises a number of questions:
Why do I have discover runner when according to your own github updates it is no longer required? 924c7ae
Why do I have jinja at all? It isn’t in any requirements file. Where did it come from?
My requirements files are largely empty. I don’t understand that. I thought this template would come with “everything I needed”, at least according to the author’s view of best practices. But instead what I got, according to pip freeze, is not at all the same as what is in my requirements files. I don’t get that.
There is apparently some question about the appropriateness of gunicorn (which is in my production.txt) in this context. See http://blog.etianen.com/blog/2014/01/19/gunicorn-heroku-django/ . I’d appreciate your thoughts about this.
I'm not entirely sure this is the right place to put this. It isn't exactly a support forum - or is it? Anyway, this is where I saw I could raise these issues with the people most directly involved. Thanks and I look forward to hearing from you.
Hi,
First of all thanks for this amazing project. I recently forked this repo and wanted to add some functionality of my own. I want to know what is the correct way to develop and test a new template. What will be the dev environment setup like?. What i can think of currently is making changes to the template and then creating a new project using the template using
django-admin startproject --template TEMPLATE_PATH and then test it. Is this the recommended approach?
This is just a suggestion....
I've been using this for a couple of years now. This also allows we to affect the level of debug, so that I can include/exclude debug_toolbar (because it adds a lot of overhead while testing).
DEBUG = int(os.environ.get('DJANGO_DEBUG', 0))
My workon alias will set DJANGO_DEBUG for me in my environment, but only on my local machine, not on production servers.
The optional toolbar part looks like:
# See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html#explicit-setup
if DEBUG > 1:
INSTALLED_APPS += (
'debug_toolbar',
)
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
DEBUG_TOOLBAR_PATCH_SETTINGS = False
# http://django-debug-toolbar.readthedocs.org/en/latest/installation.html
INTERNAL_IPS = ('127.0.0.1',)
When I want to run a test, I can turn off the toolbar with
DJANGO_DEBUG=0 manage test...
The problem with Django's startproject command is that it is very limited. Even after a project is created, you have to make changes across at least three files. Cookiecutter fixes those issues, injecting names, emails, and other values as needed.
I noticed that the Readme is instructing users to run the command like so.
$ django-admin.py startproject --template=https://github.com/twoscoops/django-twoscoops-project/archive/master.zip --extension=py,rst,html icecream_project
But then I also noticed that the develop branch is about 30 commits ahead of the master. Wouldn't it be best to use the develop branch?
$ django-admin.py startproject --template=https://github.com/twoscoops/django-twoscoops-project/archive/develop.zip --extension=py,rst,html icecream_project
Additionally in the book you guys mention using the Unipath
package and then here it's all using built-in parts of the standard library, this seems confusing to me because the pattern in the book using the standard library doesn't match what is done here. Could I get some clarification?
The link to https://docs.djangoproject.com/en/1.8/ref/contrib/csrf/ in section 11.3 (pg 138) ends up as a page not found. Correct URL should be https://docs.djangoproject.com/en/1.8/ref/csrf/
I have install a fresh project with your instruction and then did
./manage shell
and tried the official email sending example:
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', '[email protected]',
['[email protected]'], fail_silently=False)
https://docs.djangoproject.com/en/dev/topics/email/
This error appears:
Traceback (most recent call last):
File "<input>", line 2, in <module>
File "/home/yaser/.virtualenvs/email_test/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
connection=connection).send()
File "/home/yaser/.virtualenvs/email_test/local/lib/python2.7/site-packages/django/core/mail/message.py", line 255, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/yaser/.virtualenvs/email_test/local/lib/python2.7/site-packages/django/core/mail/backends/console.py", line 26, in send_messages
self.stream.flush() # flush after each message
AttributeError: 'FakeStream' object has no attribute 'flush'
When i install just fresh Django. the error did not appear. I'm beginner in Django development I hope I could give you more details.
In the base.py settings STATIC_ROOT is set to normpath(join(SITE_ROOT, 'assets')), when I think it really should be normpath(join(SITE_ROOT, 'static')). The STATICFILES_DIRS refers to a "static" folder not an "assets" folder.
Might be my inexperience with virtualenvwrapper
but I found the directions ...
$ mkdir icecream
$ mkvirtualenv -a icecream icecream-dev
$ cd icecream && add2virtualenv `pwd`
to be confusing as when I did my mkvirtualenv
the directory icecream
was created and made the current working directory - hence the cd to icecream
on the next line was redundant.
Perhaps this is my non standard virtualenvwrapper
configuration or perhaps virtualenvwrapper
behaviour has chnaged ?
I'm using Python 2.7.3 on Ubuntu 12 and the venv packages are
virtualenv==1.11.4
virtualenv-clone==0.2.4
virtualenvwrapper==4.2
References ticket #44
Files likely to be created:
requirements/dotcloud.txt
project_name/project_name/settings/dotcloud.py
Hi,
I created a fork with support for SASS, including Bootstrap SASS and grunt watch
to compile it all when the files change.
I looked at the fork mentioned in #14 and it seems is no longer active and a year old so I went ahead and did mine here https://github.com/julio-menendez/django-sass-project.
I'm planning in making another one from there with rest-framework and AngularJS integrated. We use all that on our projects but seemed more usable to have one fork with just SASS and another one with all 3 (SASS, AngularJS and rest-framework).
Just letting you know in case someone needs it too.
In the book you recommend to install Sphinx globally which I did.
Doesn't it make more sense to remove it from the local.txt requirements? because it also takes a load of dependencies. Which I don't need installed globally and in every environment.
In 2 Scoops of Django for 1.6, on page 153 (Ch. 12.3.3), you suggest using "select_related()" to minimize hits to the database in template renders. You show the template code, but I'm not sure how I'm supposed to use "selected_related()" in the View. An example View would be GREAT! Thanks.
The static and templates folders don't match with the paths provided at settings/base.py
Problems with the Windows section in the ReadMe file:
site-packages
, not site-directory
, and on windows, there is no python2.7
in the path)Also, it would be great it you would explain what this code does(why it's needed).
One more minor issue: the ReadMe file refers to django 1.5, but the django 1.6 book points here too.
Reference #44
requirements/gondor.txt
project_name/project_name/settings/gondor.py
I've implemented the changes suggested in Chapter 5 to the settings file but using multiple files give errors (see below):
django-admin.py runserver --settings=testapp.settings.local
ImportError: Could not import settings 'testapp.settings.local' (Is it on sys.path?): No module named testapp.settings.local
Do I now have to add each Django project to the python path manually to get this to work?
References #44
Files to be created:
requirements/heroku.txt
project_name/project_name/settings/heroku.py
Unfortunately, Heroku wants to see pylibmc in the root requirements.txt. Maybe @jacobian, or @kennethreitz know how to fix this?
Just a question,
Why development settings and requirements are called in local.py
and local.txt
, instead of development.py
and development.txt
?
Not sure how to correct this, the make.bat can be done by setting the bat into the "--extensions=bat" but the Makefile has no extensions so I don't know how to make it be rendered.
Hi,
I'm following the book, I'm reading Chapter 7 and I would like to have model.py and data to query the data and see how some of the methods explained in the book works. Does anyone know where to download the DB with data and model.py?
now if launch the command RUN SERVER, i get this error
DatabaseError at / admin /
no such table: django_session
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.5.1
Exception Type: DatabaseError
Exception Value: no such table: django_session
From #44
Requires the following files, and possibly changes to README.rst
requirements/openshift.txt
project_name/project_name/settings/openshift.py
Hello. I just pushed a sass feature to my fork of your project. Visit https://github.com/Doca/django-twoscoops-project.git
Such a great book and great Project template! Thanks for your work!
I'm not so into the collaboration thing with git yet. If you have an idea how i can integrate this sass thing in a more decent way just tell me how and i will do it ;-)
Deleted the redunant http:// in url.
This is same as #19. I'm very sorry about this mistake. Close this issue.
I was trying to push my project to Heroku, when I bumped into two road blocks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.