I have just installed the Pinax but i'm very confused now.
in my structre
i have two directories
mysite and mysite-env
I dont why i have two directories. I just followed the installitation directions
in mysite,
<project-root>
apps/
__init__.py
deploy/
__init__.py
fcgi.py
wsgi.py
fixtures/
initial_data.json
locale/
...
requirements/
base.txt
project.txt
sitemedia/static // I move static file from mysite-env to here
...
templates/
_footer.html
homepage.html
site_base.html
__init__.py
manage.py
settings.py
urls.py
However,
default index page is in mysite-env/lib/python2.6/site-packages/pinax_theme_bootstrap/templates/banner_base.html
Should i manage my site from mysite ?
Pinax uses virtualenv to prevent messing up your local python libs by your project dependency.
So, launch the site with $ source mysite-env/bin/activate it will be fine. If you really hate mysite-env, just skip the virtualenv part.
Related
I have one big Django project consisting out of several small apps, independent from each other but partly sharing the same database or/and models.
All the apps are created with python manage.py startapp myappa so they have their own urls.py and views.py.
I started using create-react-app for the front end for two of those apps and connected them successfully by turning the index.html of the react project into a template and serve it through the views.py (more here).
Now each one of these create-react-app projects has its own build folder which's path I include in the STATICFILES_DIRS in settings.py to collect the static files.
It looks like this:
static/
templates/
myappa/
build/
static/
index.html
...
myappb/
build/
static/
index.html
...
Now, I was wondering if there is a way to have only one build folder that contains all built files respectively to their projects something like:
myappa/
myappb/
static/
templates/
build/
myappa/
static/
index.html
...
myappb/
static/
index.html
...
I'm imagining that this folder would live on the same level as the the static folder and the appa and appb folders.
One way, since by default I can't have the build folder outside the project folder structure(?) and I don't want to eject the project, I manually move all the build folders a couple of levels up so that it is on the same level as the app folders after the build process. That way I only have to include one path into to STATICFILES_DIRS. But I'm wondering if there is an automatic way of doing this.
I've been looking at other projects of django and React but unfortunately, most are rather small so they don't cover this case.
I was wondering if anyone had the same thoughts or maybe some nice big projects on github I can have a look at? Or am I wrong and by default having its own create react app in the separated apps makes sense?
I want to place django app files into generated Django project folder .
MyProject/
MyProject/
settings.py
urls.py
here i want to insert my Django app files like, views.py, admin.py, models.py etc into same MyProject folder itself. we can do the same by copy paste after app was created. but i want to know is their any magic we can achieve the same while executing this command?
django-admin startapp MyApp <directory>
I dont want to create Myapp folder instead Myapp/* should be move onto Myproject/ itself. without doing copy paste thing.
so finally i want my Project folder should be like this,
MyProject/
MyProject/
admin.py
models.py
settings.py
urls.py
views.py
command to run from same direcory. If you change directory then change in path also:
django-admin startproject myproject
django-admin startapp myapp myproject\myproject\
command sample:
E:\write here>django-admin startproject myproject
E:\write here>dir myproject\myproject
Volume in drive E has no label.
Volume Serial Number is ****-****
Directory of E:\write here\myproject\myproject
03-06-2017 11.53 AM <DIR> .
03-06-2017 11.53 AM <DIR> ..
03-06-2017 11.53 AM 3,103 settings.py
03-06-2017 11.53 AM 766 urls.py
03-06-2017 11.53 AM 396 wsgi.py
03-06-2017 11.53 AM 0 __init__.py
4 File(s) 4,265 bytes
2 Dir(s) 80,954,753,024 bytes free
E:\write here>django-admin startapp myapp myproject\myproject\
CommandError: E:\write here\myproject\myproject\__init__.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
don't worry about above error because it is just notifying you that __init__.py is not to be overwrite.
When I initially created my Django project, I had this file folder structure:
project/
project/
manage.py
settings.py
...
In the topmost folder I have my git repo initialized as well as my vitual environment.
I want to collapse the top folder level (as if I had run `django-admin.py startproject .':
project/
manage.py
settings.py
However, when I tried to do this manually, it suddenly can't find the settings module. It's still looking for it at project.settings. Where might this be hardcoded?
When I run python manage.py runserver, I get this error:
ImportError: Could not import settings 'module.settings' (Is it on sys.path?): No module named settings
When I run django-admin.py help <some subcommands> I get this error:
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
I'm sure somewhere I have the path to the settings set, but I can't find it. Any ideas?
I've used these places in the past:
You might have set the PYTHONPATH environment variable in you .bashrc / .bash_history / some other shell startup file
You might have set said variable in your virtualenv in the $virtualenv/bin/activate script
You migth have symlinked your project from within $virtualenv/lib/pythonx.y/site-packages
The error is because of the following possibilities:
You aren't running the command from your project root i.e. project/ , not project/project.
Have not the project root i.e. project/ added to PYTHONPATH
Your manage.py isn't at project root i.e. project/ , instead it is in project/project.
Possible Solutions:
add the project root i.e. project/ to PYTHONPATH - because manage.py tries to do the equivalent of an import project.settings and for that to happen it needs to find project in sys.path
if you have the project root (project/) listed in PYTHONPATH - issue must be manage.py importing settings in form project.settings, where you have them both at the same level i.e. it has to be just settings - so move your manage.py one level up, to the project root, project/ from the current project/project.
set DJANGO_SETTINGS_MODULE to project.settings.
project.settings indicates that the setting module is one dir lower than manage.py - as in your case you're having both manage.py and settings.py at the same level i.e. project/project/
That is you have not used the default django project structure.
Anyways you can check /export settings just before running 'runserver' command: (from Official Django documentation - setting DJANGO_SETTINGS_MODULE)
Example (Unix Bash shell):
export DJANGO_SETTINGS_MODULE=mysite.settings
django-admin.py runserver
Example (Windows shell):
set DJANGO_SETTINGS_MODULE=mysite.settings
django-admin.py runserver
Suggestion: Try to abide by the conventional project structure (atleast till you become an expert). i.e. keep manage.py one dir level up the other project files .. settings.py, urls.py , etc
So I'm testing out Heroku with a dummy app called hellodjango, and pushing everything to git.
Added my .gitignore file (tell me if I'm wrong, I created a text document called django.gitignore, and the contents are 1 line, no spaces, venv*.log*.pot*.pyclocal_settings.py.
Not sure what I'm doing wrong, but here is my directory
hellodjango/
django.gitignore
manage.py
requirements.txt
hellodjango/
__init__.py
__init__.pyc
settings.py
settings.pyc
urls.py
urls.pyc
wsgi.py
wsgi.pyc
venv/
Include/
Lib/
Scripts/
So I don't want to stage any .pyc files or the venv folder.
In my command line, I enter
git init
Initialized empty Git repository in /Users/Chris/hellodjango/.git/
>git add .
>git status
When I enter git status, all of the files in venv and .pyc are staged. Why is .gitignore not working?
The gitignore file needs to be named only .gitignore without a django in front of the dot.
You can find more information about ignoring files and possible patterns supported in the ProGit book on the official website: ProGit Chapter 2-2.
I'm new to Django. I'm using Django with Eclipse. I've created a Django project using Eclipse (called "Django_Test_Project"). I've also created a PyDev project outside of Eclipse, using the command line (called "polls"). It has models.py, views.py, and tests.py.
I created "polls" using the following command:
manage.py startapp polls
I want use Eclipse to add "polls" as a second project to "Django_Test_Project". How do I do that with a project that was created outside of Eclipse? Eclipse doesn't recognize "polls" as a project, probably because the project files are missing in "polls".
Any help is appreciated. Thanks.
You are working on the Django tutorial, right? First of all, your terminology is not correct. You confuse a project with an application or app for short. It's no surprise that Eclipse doesn't recognize polls as a project, because it's not a project but an app.
In Django 1.4.1, the standard structure for a project called mysite is this:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
Your polls app should go in the same directory where the file manage.py is located:
mysite/
manage.py
polls/
__init__.py
models.py
tests.py
views.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
You can just move the polls directory into the mysite directory using the Windows Explorer, Finder, Terminal etc. (depends on which OS you are running on). After refreshing the project view in Eclipse, your polls app should show up. In any case, you should read the Django tutorial more carefully as it basically answers your question already.
Additionally, take a look at this thread that explains the difference between projects and apps in a bit more detail.