How to install the Django-Simple-Blog package into an existing Django project? - django

I found a similar question, with this reply: "...django-simple-blog is an app, meaning you install it within an existing project."
But I need more explanation. Can someone explain to me how to "install" an app within an existing Django project? And what it means to do so? (I use Pycharm).

Django allows us to add multiple apps.
For eg.: if we want to add multiple social authentications, we can install django-allauth
install a thirdparty app
pip install django-allauth # or any other app you like.
or create a new one
django-admin startapp simpleblog
then we modify our settings.py in our django project.
INSTALLED_APPS = [
...,
'allauth', # add the app name here.
'simpleblog',
]
You can refer following to learn more about Django:
https://docs.djangoproject.com/en/2.1/
https://tutorial.djangogirls.org/en/
https://www.twoscoopspress.com/products/two-scoops-of-django-1-11

Related

How to use wordpress + django to build a website

I have a wordpress website ,and i want to add more functionality with django framework.Is it posible to build a hybrid website with Wordpress and Django..???
Let’s start with the configuration. The first thing is that you need to install WP REST API v1 plugin inside your WordPress site and enable it.
Then you need to install Django WordPress Api library inside your django application
pip install django-wordpress-api
After that, add wordpress_api inside the installed apps
INSTALLED_APPS += ('wordpress_api',)
Also, if you are using DWA Views (explained later) you need to add the wordpress_api urls in your application urls
url(r'^blog/', include('wordpress_api.urls')),
Finally, you need to set up the DWA required settings; WP_URL and BLOG_POSTS_PER_PAGE.
WP_URL = https://your-wordpress-app.com/
BLOG_POSTS_PER_PAGE = number-of-blogs-to-display-per-page
and that’s it.
You can follow this link

Creating migrations for a reusable Django app

I am writing a reusable Django app and having problems creating migrations.
I have looked at this question, and I'm still confused. I have the following sort of directory structure:
django-mycleverapp/
django-mycleverapp/django_mycleverapp/
django-mycleverapp/django_mycleverapp/__init__.py
django-mycleverapp/django_mycleverapp/apps.py
django-mycleverapp/django_mycleverapp/models.py
django-mycleverapp/django_mycleverapp/urls.py
django-mycleverapp/django_mycleverapp/views.py
django-mycleverapp/example/
django-mycleverapp/example/manage.py
django-mycleverapp/example/example/
django-mycleverapp/example/example/__init__.py
django-mycleverapp/example/example/settings.py
django-mycleverapp/example/example/urls.py
django-mycleverapp/setup.py
As you can see, the directory "django_mycleverapp" contains my reusable app and the directory "example" contains a test project.
I include the models of "django_mycleverapp" in the INSTALLED_APPS section of the settings for "example".
However, running python ~/example/manage.py makemigrations django_mycleverapp doesn't build any migrations.
Any suggestions?
How am I meant to have a test project that will build migrations in "/django-mycleverapp/django_mycleverapp/migrations"?
Your app should be in the directory of your project. Your directory hierarchy should look like this.
django-mycleverapp/
django-mycleverapp/example/
django-mycleverapp/example/django_mycleverapp/
django-mycleverapp/example/django_mycleverapp/__init__.py
django-mycleverapp/example/django_mycleverapp/apps.py
django-mycleverapp/example/django_mycleverapp/models.py
django-mycleverapp/example/django_mycleverapp/urls.py
django-mycleverapp/example/django_mycleverapp/views.py
django-mycleverapp/example/manage.py
django-mycleverapp/example/example/
django-mycleverapp/example/example/__init__.py
django-mycleverapp/example/example/settings.py
django-mycleverapp/example/example/urls.py
django-mycleverapp/example/setup.py
If you do not want your app to be part of your "example" project, but rather want it to be separated and used by your project "example", you'll have to install it in your project using pip (this requires to have a setup.py at the root of your app).
For instance if you have published your app on a git repository "https://gitlab.com/myuser/myproject.git", you can add to our requirements.txt:
git+https://gitlab.com/myuser/myproject.git#v1.0#egg=myapp_name
If you don't have your app published on a git repository yet, you can add the absolute path to your app to you requirements.txt:
/path/to/django-mycleverapp/django_mycleverapp/
Don't forget to work in a virtualenv when you use pip.

I am unable to install django registration

i tried installing django registration:
http://django-registration.readthedocs.org/en/latest/
but i get an error: no module named registration
whenever i load my site.
what can I do?
You should add it to the INSTALLED_APPS list :
Begin by adding registration to the INSTALLED_APPS setting of your
project, and specifying one additional setting:
ACCOUNT_ACTIVATION_DAYS This is the number of days users will have to
activate their accounts after registering. If a user does not activate
within that period, the account will remain permanently inactive and
may be deleted by maintenance scripts provided in django-registration.
This is from the required settings section :
http://django-registration.readthedocs.org/en/latest/quickstart.html#required-settings
So these are the steps that worked for me.
Install using pip
$pip install django-registration
Make sure the django-registration is installed.
$pip list
django-registration should show up.
Add 'django-registration' to INSTALLED_APPS tuple
Hope this helps.

How do I implement django-articles app into a new project via pip?

I'm trying to install the following django app from the cheeseshop:
https://bitbucket.org/codekoala/django-articles/overview
This is my first day of Django-ing and I'm unsure what to do to get the app's folder populated inside my project.
So far, I've pip installed the app into my virtualenv. This is verified by opening a python shell and getting no errors when I run "import articles"
I've edited the settings.py file and added it to the list of installed apps. I believe this to be OK as I can then run runserver without any "module not found" errors.
syncdb also ran fine.
Where do I go from here?
ie, I would like to have a section of the website called News which uses this app. I have no routes or other apps configured yet, just a clean Django with psycopg2.
EDIT: Enabling the default admin site, I can manage the Articles there, but still unsure of how these will be displayed on the site when I have no app folder created for them. When trying to startapp articles, I'm warned it's conflicting name with an existing module..
No need to create a new app called articles. As you are able to import articles via the python console you have successfully installed it. You can find it in your virtualenv folder in the folder site-packages:
/path_to_your_virtualenv/.virtualenvs/<virtualenvname>/lib/<pythonversion>/site-packages
You can use this app, installed via pip, as it is an app which lives in your project folder.
You just need to include the articles urls in your own urls.py. Since you say you want it under News, this would do fine:
urlpatterns = patterns('',
(r'^news/', include('articles.urls'),
)
Note though that the readme for the articles app implies that you'll need to create your own base template for it to inherit from. Just create a base.html file in a directory called templates under your project, give it a basic HTML structure, and put in {% block content %}{% endblock %} in the relevant place (and the same for the other blocks mentioned in the readme).
You should probably do the Django tutorial anyway, to understand exactly what's going on with the URL and the templates.

Where do I install Twitter Bootstrap for Django - main or static folder?

I'm new to this, and experimenting with a Django site that has both a main folder and a static media folder. I'm trying to install django-bootstrap, but not sure how to go about it.
I'm using the instructions in this Django Bootstrap page.
First, do I run
pip install -e git+git://github.com/earle/django-bootstrap.git#egg=bootstrap
from the terminal in the main folder, or static media folder?
Second, where do I insert the usage code?
from bootstrap.forms import BootstrapForm, Fieldset
class LoginForm(BootstrapForm):
class Meta:
layout = (
Fieldset("Please Login", "username", "password", ),
)
username = forms.CharField(max_length=100)
password = forms.CharField(widget=forms.PasswordInput(), max_length=100)
The above is obviously only for login fields, but will I need to include that import language in many files, or just one main one?
EDIT for clarity: My host is WebFaction, which uses a Domain + Webapp = Website structure for site hosting. One of their recommended methods for Django installs is to set up the main Django site in one webapp, and a static media folder in another: see here for details.
I am not the site creator or installer, but have copied the site over into a test version so I can mess with its design while the programmer is unavailable for an extended period. I'm looking into Django Bootstrap as a way to make it easier to redesign the site. My skills are obviously limited, but I'm willing to read/learn!
Django-bootstrap is a Django "app", installed as a python package. Since webfaction doesn't do virtualenv, you should be ok* to just ssh in and run
pip install -e git+git://github.com/earle/django-bootstrap.git#egg=bootstrap
from wherever. This will install django-bootstrap to your global python site-packages folder.
Next, you'll need to make sure django knows about it, which you do by editing the settings file and adding it to INSTALLED_APPS, e.g.
INSTALLED_APPS = (
# ... other things
'bootstrap',
# ... maybe more things
)
Any python file that uses the BootstrapForm and Fieldset classes, will require the import statement at the top of it. A python module (file) will only know about a) what you declare directly in it, and b) what you explicitly import. I don't know how you got anywhere using python without knowing that, because it's pretty important. Consider reading up on the subject.*
Anyhow, the only thing django-bootstrap seems to do is change django's form-rendering code to output HTML that is more compatible with Bootstrap. You will still need get twitter-bootstrap yourself, and make sure that you use the media, i.e. the css, js and images, from it. Put the bootstrap media in your static app.
http://twitter.github.com/bootstrap/
*Edit: I just read the last bit of your post and now I feel like a big meanie. So, here are some extra resources that I recommend you read through.
Python samples: http://wiki.python.org/moin/SimplePrograms
Django's Tutorial: https://docs.djangoproject.com/en/1.3/intro/tutorial01/
I'm afraid I don't quite understand the question. pip install will install this in de site-packages folder, not in the location you are running the command from.
The code is a form so would go into a forms.py within the app you are trying to make. That form inherits from BootstraForm, so you would just use the LoginForm where you want and it would be a BootstrapForm.